ios 判断数字大小_iOS开发积累2

b8416554920337eb3f6028d8cbdae4a4.png

3、设备的CPU架构简介

模拟器:

  • 4s~5 : i386
  • 5s~6plus : x86_64

真机:

  • 3gs~4s : armv7
  • 5~5c : armv7s (静态库只要支持了armv7,就可以跑在armv7s的架构上)
  • 5s~6plus : arm64

4、derived data

xcode缓存derived data,有时遇到修改完库代码了,但是编译完还是旧库文件,可以把缓存删掉看看;

derived data的保存目录可以在xcode - Preferences - locations 里面设置,

Default使用的是默认路径/Users/xxx/Library/Developer/Xcode/DerivedData/

Relative使用的是project或者workspace的路径,推荐用这个

6、第三方库管理工具cocoaPods

pod search xx第三方库名称:查找第三方库

vim Podfile,创建并编辑pod文件。按i进入编辑状态,按ESC退出编辑态,按shift+zz退出vim。

pod install --verbose --no-repo-update,开始安装配置在pod文件中的第三方库。

import第三方库时,希望有提示,解决这个问题的办法是在工程的Build Settings搜索Search,然后在User header search paths中添加$(SRCROOT)并选择recursive。

参考:

安装:http://www.jianshu.com/p/1711e131987d

解决慢的问题:http://www.cocoachina.com/ios/20170208/18645.html

使用:

http://www.jianshu.com/p/82d0ba43f8c3

http://blog.csdn.net/zhongtiankai/article/details/71330111

为自己的项目创建 podspec 文件

http://blog.devtang.com/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/

pod install时错误(――― MARKDOWN TEMPLATE。。。):

https://blog.csdn.net/xiaoliuxingzi/article/details/22742227

pod update 命令 cocoapods遇到error: RPC failed; curl 56 SSLRead() return error -36问题:

https://blog.csdn.net/qq_32873193/article/details/79849353

7、AFNetworking

网络错误data提示转为字符串:http://www.cnblogs.com/HMJ-29/p/6066631.html

追加acceptableContentType:

serializer.acceptableContentTypes = [serializer.acceptableContentTypes setByAddingObject:@"image/jpg"];

AFNetworking存在一个内存泄漏的问题,有两种解决方案,

一种是在网络请求结束后调用,invalidateSessionCancelingTasks

另一种是使用把 AFHTTPSessionManager 寫成 singleton

参考:

http://nelson.logdown.com/posts/2017/03/28/retain-cycle-in-afnetworking

判断网络状态,可以这样:

先startMonitor,然后通过networkReachabilityStatus来判断;

参考:

http://boitx.org/2017/08/27/afnetworking-isreachable-%E7%BC%BA%E9%99%B7/

AFNetworking不支持32位架构,valid architecture要设置为arm64

参考:

http://blog.csdn.net/yidu_blog/article/details/52682165

错误输出:

https://www.jianshu.com/p/afdb5508c5b5

11、自定义相机

不使用系统相机,需要展示自己的UI时参考:

http://www.jianshu.com/p/8b28892bae5a

相机捕捉:

https://objccn.io/issue-21-3/

相机自动对焦:

http://blog.csdn.net/lyq4436/article/details/73498362

http://www.jianshu.com/p/07286beb7a9f

AVCaptureSessionPreset在设备上的像素列表:

https://stackoverflow.com/questions/19422322/method-to-find-devices-camera-resolution-ios/31964333#31964333

iOS拍照后图片自动旋转90度的完美解决方法:

https://www.jb51.net/article/101047.htm

15、时间格式

dateFormatter.AMSymbol=@"上午"

dateFormatter.PMSymbol=@"下午"

参考:

http://blog.csdn.net/jeffasd/article/details/51879783

NSCalendarUnitWeekOfYear & NSCalendarUnitWeekOfMonth区别:

https://stackoverflow.com/questions/22341048/difference-between-nscalendarunitweekofyear-nscalendarunitweekofmonth/25555560#25555560

17、NSString中提取出数字

使用NSScanner

http://blog.csdn.net/trandy/article/details/10003993

常用正则表达式:

http://www.jianshu.com/p/13774c6bbdaa

19、deviceOrientaion转UIImageOrientation

- (UIImageOrientation)rotationNeededForImageCapturedWithDeviceOrientation:(UIDeviceOrientation)deviceOrientation { UIImageOrientation rotationOrientation; switch (deviceOrientation) { case UIDeviceOrientationPortraitUpsideDown: { rotationOrientation = UIImageOrientationLeft; } break; case UIDeviceOrientationLandscapeRight: { rotationOrientation = UIImageOrientationDown; } break; case UIDeviceOrientationLandscapeLeft: { rotationOrientation = UIImageOrientationUp; } break; case UIDeviceOrientationPortrait: default: { rotationOrientation = UIImageOrientationRight; } break; } return rotationOrientation; }

21、相机、相册的权限

以相册举例:

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

if (status == PHAuthorizationStatusAuthorized) {

// 用户同意授权

}else {

// 用户拒绝授权

}

}

使用上面这个方法就可以判断相册的权限情况,应用第一次是系统弹出提示,这个方法会一直等用户选择后获取到授权情况。

系统权限弹窗提示,如果选择拒绝,默认不会退出当前页面。想要达到这个效果,可以用[PHPotoLibrary authorizationStatus]先获取当期状态是否为NotDetermined。

参考(iOS相册权限、相机权限、麦克风权限):

http://www.jianshu.com/p/b4fbc57c84b0

另外,系统相册的增删等监听,可以参考(PhotoKit简介)

http://www.jianshu.com/p/3c59844df301

更多权限参考:(iOS开发中的这些权限,你搞懂了吗?)

http://www.jianshu.com/p/27e57922232b

22、自定义view的两种方式比较???

占位

23、序列化和反序列化

通过runtime来实现,并通过宏定义来做到方便使用

http://www.jianshu.com/p/fed1dcb1ac9f

iOS: 把对象直接转化成NSDictionary或JSON

参考:

http://zqlicoder1314.blog.51cto.com/3014999/1318672

ps:

直接使用YYModel更简单

https://blog.csdn.net/u010105969/article/details/79128154

iOS 数据持久化之plist:

http://blog.csdn.net/hello_hwc/article/details/45441609

26、UICollectionView

设置列数:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)self.colletionView.collectionViewLayout;

int column = 4;

float space = flowLayout.sectionInset.left + flowLayout.sectionInset.right + (flowLayout.minimumInteritemSpacing * (column - 1));

float cellWidth = floorf(([UIScreen mainScreen].bounds.size.width - space) / column);

return CGSizeMake(cellWidth, cellWidth);

}

参考:https://gxnotes.com/article/62374.html

collectionview动画:

https://objccn.io/issue-12-5/

28、NSString实用功能

从NSString中提取数字 NSScanner

http://blog.csdn.net/trandy/article/details/10003993

字节大小显示byte,K,M,G等

+ (NSString *)transformedByteSize:(long long)byteSize

{

double convertedValue = (double)(byteSize);

int multiplyFactor = 0;

NSArray *tokens = [NSArray arrayWithObjects:@"bytes",@"K",@"M",@"G",nil];

while (convertedValue > 1024) {

convertedValue /= 1024;

multiplyFactor++;

if (multiplyFactor >= tokens.count - 1) {

break;

}

}

return [NSString stringWithFormat:@"%.2f%@",convertedValue, [tokens objectAtIndex:multiplyFactor]];

}

计算字符串长度(英文字母算1,汉字等算2)

http://www.cnblogs.com/swallow37/archive/2013/05/05/3060865.html

文本批量替换技巧:

通过正则筛选出匹配结果后,把结果倒序下,然后替换就不会造成string变化导致的后面替换失败。

29、js交互方案

1)使用JavaScriptCore

有两个重点:

怎么获取JSContext:

JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

或者:

- (void)webView:(UIWebView *)webView didCreateJavaScriptContext:(JSContext *)ctx

注入时机:

在didCreateJavaScriptContext后

可直接注入方法xxMethod,也可以注入对象。

比如注入对象myApp的话,网页上调用myApp.xxMethod,或者window.myApp.xxMethod

参考:

http://www.skyfox.org/javascript-ios-navive-message.html

参考:

iOS中JavaScript 与OC交互

http://www.jianshu.com/p/59242a92d4f2

UIWebView-TS_JavaScriptContext

https://github.com/TomSwift/UIWebView-TS_JavaScriptContext

网页JS与OC交互(JavaScriptCore)

http://www.jianshu.com/p/12c77d85b295

JavaScriptCore在实际项目中的使用的坑

http://blog.csdn.net/u011296699/article/details/50435559

JavaScript和Objective-C交互的那些事(续)

http://www.jianshu.com/p/939db6215436

2)WKWebview

WKWebView与JS交互

http://blog.csdn.net/shenhuaikun/article/details/61916761

WKWebView与js交互之完美解决方案

http://blog.csdn.net/hanhailong18/article/details/69102820

WKWebView使用及注意点

http://www.jianshu.com/p/9513d101e582

wkwebview获取的实际高度不准确:

js 获取的高度 只适合 简单页面, 如果有大量图片 获取的高度往往是不对的

http://www.cocoachina.com/bbs/read.php?tid-1712843-page-1.html

WKWebView 那些坑(转自 腾讯Bugly):

http://www.jianshu.com/p/bb20ff351fa2

3)点击webview上的按钮 触发跳转到app的其他页面

有两种方案:

1是url拦截,这个需要服务端进行版本适配

2是addScriptMessageHandler:self,注意使用完要remove,否则会内存泄露

30、UIDeviceOrientation

如果锁定竖屏了,也就是关闭了设备旋转,通过[UIDevice currentDevice].orientation获取的就都是竖屏的。

这样,可以通过加速计得到x,y,z来判断横竖屏。核心是比较x,y的绝对值。

怎么获取加速计和陀螺仪参考:

http://www.jianshu.com/p/5bf81ef8d35a

31、NSArray中英文排序

sortedArrayUsingComparator,核心在于比较的算法;

1)逐个提取字符,判断isascii则用compare比较,否则用localizedCompare来比较,不过如果setting语言设置的是英语,但是app中又需要用到中文的排序,则中文排序会失效;

2)提取中文首字母,再进行排序,多音字则不准

推荐使用方法1。

35、系统分享(Share Extension)

属于App Extension中的一种;

可自定义UI;

和containing app通过App Group进行数据交换;

Extension和containing app需要共享代码时,可以这样,建立一个framework,默认创建的话会是动态的,可以手动改成静态的,另外在build phase里添加需要用到的.m文件。

给Extension加图标:

Right click your app extention folder in the Xcode browser on the left -> New File... -> Asset Catalog (Resource).

Then add a App Icon to your asset catalog. Select asset catalog in the Xcode browser -> + -> App Icons & Launch Images -> New iOS App Icon -> Set name: AppIcon.

Last step: You have to set the Asset Catalog App Icon. Go to Build Settings of your extention and search for: Asset Catalog App Icon Set Name and enter AppIco.

参考:

https://my.oschina.net/vimfung/blog/707448

1)CFBundleDocumentTypes的属性说明

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685

2)System-Declared Uniform Type Identifiers

https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1

3)App Extension Keys

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AppExtensionKeys.html#//apple_ref/doc/uid/TP40014212-SW1

37、静态库、动态库、Framework

参考:

http://www.cocoachina.com/ios/20141126/10322.html

http://ios.jobbole.com/89871/

target dependencies:

A dependency is another target that must be built before the current target can be. For example, if you have an app target and a framework target, the app target can have the framework target as a dependency, to ensure that the framework is built first. That is, the app target "depends" on the framework.

38、AES加密

ios和android实现相同密文,需要统一几个参数:

密钥长度(Key Size)

加密模式(Cipher Mode)

填充方式(Padding)

初始向量(Initialization Vector)

参考:

iOS与Java的同步实现:

http://blog.csdn.net/coyote1994/article/details/52368921

iOS的各种加密方法使用简介

http://blog.csdn.net/zy_flyway/article/details/48030723

39、NSLocalizedString

在没有Localizable.strings的情况下,这样使用也可以,此时就直接显示@"xxx"

NSLocalizedString( @"xxx", nil);

40、CoreData

多表关联 : http://www.jianshu.com/p/e9f3b5e0cd19

基础使用demo:http://www.jianshu.com/p/0ddfa35c7898

Coredata版本升级和数据库迁移:http://www.jianshu.com/p/49872694e0b3

MagicalRecord:

MagicalRecord的使用:http://www.jianshu.com/p/07cd30f2d1e1

深入浅出MagicalRecord : http://childhood.logdown.com/posts/211076/easy-magicalrecord-04

Tutorial :https://www.raywenderlich.com/56879/magicalrecord-tutorial-ios

41、SDWebImage

除了可以用来显示网络图片外,还可以用来缓存本地图片,支持缓存到内存和磁盘中

[[SDImageCache sharedImageCache] storeImage:image forKey:@"smile-key" completion:^{

NSLog(@"save image");

}];

[[SDImageCache sharedImageCache] removeImageForKey:@"smile-key" withCompletion:^{

NSLog(@"remove image");

}];

self.imageView.image = [[SDImageCache sharedImageCache] imageFromCacheForKey:@"smile-key"];

源码阅读参考:

http://www.cocoachina.com/ios/20170511/19252.html

使用SDWebImage和YYImage下载高分辨率图,导致内存暴增的解决办法:

http://blog.csdn.net/guojiezhi/article/details/52033796

44、YYLabel

//这个属性必须设置,多行才有效(不过具体-20还是多少,这个很不准,-20情况大概左右间隔都15左右)

yyLabel.preferredMaxLayoutWidth = kScreenWidth -20;

45、UIImage

图片压缩技巧(压+缩)

UIImageJPEGRepresentation(image, 0.0),和 UIImagePNGRepresentation(image); 是压的功能。

[sourceImage drawInRect:CGRectMake(0,0,targetWidth, targetHeight)] 是缩的功能。

参考:

http://www.jb51.net/article/89491.htm

ps:

使用UIImageJPEGRepresentation(imageOrigin, 1)连续压缩5遍,如果压缩比例为1,反而越压越大,而小于1的话,则连续5次的结果都一样,结论是只需要压一次。

甚至与,先用0.8压完变小,再用1压又变大了,结论是关键在最后的上传时,使用UIImageJPEGRepresentation(image, 0.8),不要为1

附上几组测试数据:

1,0.6,1

before : image length = 1110.000000

after : image length = 183.000000

upload : image length = 684.000000

10.60.8

before : image length = 1110.000000

after : image length = 183.000000

upload : image length = 251.000000

10.60.7

before : image length = 1110.000000

fter : image length = 183.000000

upload : image length = 224.000000

10.80.6

before : image length = 1110.000000

after : image length = 280.000000

upload : image length = 177.000000

10.70.8

before : image length = 1110.000000

after : image length = 239.000000

upload : image length = 260.000000

48、NSString基本上整个文件都有非空说明,传nil就崩溃

NS_ASSUME_NONNULL_BEGIN

49、setObject:forKey:和setValue:forKey:区别

setobject中的key和value可以为除了nil外的任何对象;

setValue中的key只能为字符串 value可以为nil也可以为空对象[NSNull null]以及全部对象;

50、集成第三方登录、分享

微信:

微信IOS的SDK:isWXAppInstalled总是返回NO?

1 iOS 9以后需要添加白名单。

2 不要以为集成了shareSDk的微信分享就不需要[WXApi registerApp:yourappid]了。

51、JSONModel的使用

@protocol TopicItemModel

@end

@interface TopicItemModel : JSONModel

@property(nonatomic, strong) NSString *id;

@property(nonatomic, strong) NSString *name;

@end

@interface PageTopicListModel : CommonPageModel

@property(nonatomic, strong) NSArray *data;

@end

52、地址选择器

54、链式API写法

参考:https://www.jianshu.com/p/ff21259a960b

55、想将页面做成可以滚动的效果

可以通过添加1层scrollview,然后添加1层view,把view设置成height比scrollview大1(这样就能滚动了),再把页面加到view上

56、NS_OPTIONS与NS_ENUM的区别

https://www.jianshu.com/p/30f76a950604

57、时间戳

服务端返回的时间戳一般就是格林威治时间的时间戳;

使用[[NSDate date] timeIntervalSince1970]返回的也是格林威治时间戳;

使用NSDateFormatter转成时间时,不用额外加时区,默认会用系统时区来转;

下面代码可以计算10天后过期的会员:

double timestamp = YHUserMgr.userInfo.regTime;

if ([NSString stringWithFormat:@"%@", @(timestamp)].length == 13) {

timestamp /= 1000.0f;

}

//9天后的时间

timestamp += 9 * 24 * 3600;

//格式化日期

NSDateFormatter * formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"yyyy-MM-dd"];

NSString *dateStr = [NSDate zwy_timeInterval2String:timestamp formatter:@"yyyy-MM-dd"];

dateStr = [dateStr stringByAppendingString:@" 23:59:59"];

NSTimeInterval newTimestamp = [NSDate zwy_timeStringToTimeInterval:dateStr formatter:@"yyyy-MM-dd HH:mm:ss"];

newTimestamp = newTimestamp / 1000;

return ([[NSDate date] timeIntervalSince1970] - newTimestamp > 0);

58、内存泄漏

在arc模式下 不是什么东西 都可以释放 例如 C-types的对象 都需要手动来进行释放 ,比如CGImageRef,不过记住(只有当CGImageRef使用CGImageCreate或CGImageRetain后才要手动release)

参考:https://blog.csdn.net/sike2008/article/details/17307533

59、Assets文件里面如果存在同名的,xcode编译会有警告

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值