--------------------sunkaikees@gmail.com-------------------

iOS 杂记

1. 这里是列表文本const(常量) extern static 等使用场景。

const NSString            * NAME_ONE = @"你好";            //全局常量,其他类中可访问 extern NSString 

static const NSString   *NAME_TWO = @"小羊";            //static 修饰 成局部变量 只能内部访问

NSString         *const WANG_NAME = @"狗";            //用此种写法代替宏(Macro)定义

在其他类文件中要想访问全局常量 :

extern NSString *NAME_ONE; 获得(NAME_ONE)

在app中可以创建一个常量类(XKConst),m文件定义各种常量

//定义常量

NSString * const CONST_NAME = @"小明";
int const SCREEN_SIZE_W = 200;

在h 文件中提供外界访问声明

UIKIT_EXTERN NSString *const CONST_NAME;
UIKIT_EXTERN int const  SCREEN_SIZE_W;

在需要用到的地方导入头文件 XKConst.h 可以直接获取SCREEN_SIZE_W 的值

2. 软件通话状态安Home健退到后台,屏幕上红色导航条显示正在通话,点击回到软件通话界面。在info.plist中设置。

<key>UIBackgroundModes</key>	
<array>	
<string>voip</string>
<string>audio</string>	
</array>

app名字

在项目中添加 InfoPlist.strings 文件,在文件中写入 CFBundleDisplayName = appName。

RGB 颜色 宏定义

#define RGB_Color(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255 blue:B/255 alpha:A]
but.BackgroundColor = RGB_Color(230,200,50,1);

navigationbar 背景颜色以及标题字体颜色

self.navigationController.navigationBar.barTintColor = RGB_Color(230,200,50,1);
[self.navigationController.navigationBar         setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

定义各种宏的规范

参照。。。。。。

统计项目中代码总行数。

终端cd 到项目目录,输入:

 find . "(" -name "*.m" -or -name "*.strings" -or -name "*.h" ")" -print | xargs wc -l  

获得某路径下的文件大小

    (1).   NSData *Fdata = [NSData dataWithContentsOfFile:fpath];
            long long   fileSize = [Fdata length];

    (2).  NSDictionary *fileAttributes = [[NSFileManager defaultManager]                                  attributesOfItemAtPath:tfpath error:NULL];
           long long  fileSize = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];

隐藏tableview多余的分割线

    - (void)setExtraCellLineHidden: (UITableView *)tableView{
        UIView *view =[ [UIView alloc]init];
        view.backgroundColor = [UIColor clearColor];
        [tableView setTableFooterView:view];
        [tableView setTableHeaderView:view];
    }

根据文字内容计算tableviewcell高度,在heightForRow 代理中返回即可。

- (CGFloat)sizeHeigtWithItem:(MHCommanFileInfo*)info {

    NSString *value = info.fileName;

    NSInteger width = [UIScreen mainScreen].bounds.size.width - 152;

    //获取当前文本的属性

    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:value];

    //_text.attributedText = attrStr;

    NSRange range = NSMakeRange(0, attrStr.length);

    // 获取该段attributedString的属性字典

    NSDictionary *dic = [attrStr attributesAtIndex:0 effectiveRange:&range];

    // 计算文本的大小

    CGSize sizeToFit = [value boundingRectWithSize:CGSizeMake(width - 16.0, MAXFLOAT) // 用于计算文本绘制时占据的矩形块

                                           options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading // 文本绘制时的附加选项

                                        attributes:dic        // 文字的属性

                                           context:nil].size; // context上下文。包括一些信息,例如如何调整字间距以及缩放。该对象包含的信息将用于文本绘制。该参数可为nil

    return sizeToFit.height ;

}

tableviewcell 滑动删除或其他的系统方法

    -(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView             editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{  
    UITableViewRowAction *rowActionSec = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault  title:@"下载"    handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
    //点击时间相关代码                                                                             
          }];

    rowActionSec.backgroundColor = [UIColor orangeColor];
    NSArray *arr = @[rowActionSec];
    return arr;
}

获取键盘高度 键盘弹出时上推界面

   S1: 注册通知

-(instancetype)init{
    if (self = [super init]) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}

    S2: 方法中改变Fram

- (void) keyboardWasShown:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    _keybordH = keyboardSize.height;

    [UIView animateWithDuration:0.3 animations:^{
        CGRect r = _botomBarV.frame;
        r.origin.y -= _keybordH;
        [_botomBarV setFrame:r];
    }];
}
- (void) keyboardWasHidden:(NSNotification *) notif
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect r = _botomBarV.frame;
        r.origin.y += _keybordH;
        [_botomBarV setFrame:r];
    }];
}

保存图片到手机相册

-(void)saveToAlbum{
UIImageWriteToSavedPhotosAlbum(_imageV.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    NSString *message;
    if (!error) {
        message = @"成功保存到相册";
    }else    message = [error description];
  //  NSLog(@"message is %@",message);
}

字符串的小方法

1. iOS版本字符串(4.3与4.3.2)比较
    NSString *str1 = @"6.1";
    NSString *str2 = @"6.0.3";
    if (![str1 isEqualToString:str2]) {
        if (([str1 compare:str2] != NSOrderedAscending)) {
            NSLog(@"str1 是高版本");
        }else {
            NSLog(@"str2 是高版本");
        }
    }else{
        NSLog(@"版本相等");
    }
   //NSOrderedAscending 文档解释 The left operand is smaller than the right operand.
2. 判断某个类名与字符串相同
     [NSStringFromClass([wid class]) isEqualToString:@"UIRemoteKeyboardWindow"]
3 . 根据字符串内容及属性字典计算所占  size
  NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13.0]};    
  CGSize size = [message.contentInfo boundingRectWithSize:CGSizeMake(200, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size;

字典倒叙排列

     NSArray *arr = [NSArray arrayWithArray:@[@"aaa",@"bbb",@"ccc"]];
     _dataArr = [[[arr reverseObjectEnumerator] allObjects] mutableCopy];

cocoaPod 使用

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end

创建自己的pod库(公有私有),注意使用时podfile 文件要添加公有地址和私有地址
地址链接

# 查看当前路径文件夹下所有文件

NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]enumeratorAtPath:[MHAppManager instance].favoritesDirectory];
for (NSString *fileName in enumerator){
NSLog(@"%@",fileName);
}

#  main函数  crash 代码定位

edite shceme --->Run -->arguments-->environment variables
添加key values :NSZoobieEnable YES
breakpoint 界面调试

# mysql 触发器/事务/存储过程/自定义函数/index原理/view作用
### 存储过程- (循环)

drop procedure if exists p_while_do;
create procedure p_while_do()
begin
declare i int;
set i = 1;
while i <= 10 do
/// TODO 循环存数据等。。。
set i = i + 1;
end while;
end;

call p_while_do();

### 错误记录

- linker command failed with exit code 1 (use -v to see invocation)
引用c++(有.cpp文件)编译的.a 文件出现了错误,原因是Xcode无法识别c++编译类型。解决方法是1.改变build Setting 中compile source as 的 according to file type(按文件类型)---> object-C++。2. 在Xcode中创建或改变一个 .m 文件为 .mm 文件,Xcode可以识别c++. [原文连接](http://blog.csdn.net/mad1989/article/details/40590371)

### bug  crash 统计

- fir          :http://fir.im
- bugHD   : http://bughd.com/doc/index

### run script

xcode 添加编译脚本 编译时执行
每次编译,build号加1

!/bin/bash

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

### ios 逆向工程

逆向就是把ios打包好的二进制包重新反编译出能看懂的代码文件,其中可以用IDA,class-dump 等工具。
如果二进制文件是加密的,还要先砸壳。
class-dump 能直接生成 .h 文件的方法名,可以大致解析app的代码结构和主要方法。
https://www.cnblogs.com/LeeGof/p/6992852.html

posted @ 2019-01-17 19:25  雪天微风吹  阅读(170)  评论(0编辑  收藏  举报