http://www.cnblogs.com/godlovexq/p/5885212.html
代码注释不能用的解决办法
这个是因为苹果解决xcode ghost,把插件屏蔽了。
解决方法
打开终端,命令运行: sudo /usr/libexec/xpccachectl
然后必须重启电脑后生效
注意:Xcode8内置了开启注释的功能,位置在这里
屏蔽杂乱无章的bug
更新Xcode8之后,新建立工程,都会打印一堆莫名其妙看不懂的Log.
如这些
subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1,
屏蔽的方法如下:
Xcode8里边 Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加字典:
(name)OS_ACTIVITY_MODE = (value:)Disable
Image may be NSFW.
Clik here to view.
在设置log选项的时候,发现可以通过在Arguments中设置参数,打印出App加载的时长,包括整体加载时长,动态库加载时长等。
在Environment Variables中添加DYLD_PRINT_STATISTICS字段,并设置为YES,在控制台就会打印加载时长。
考虑到添加上述内容在Xcode8后,真机调试可能出现异常,大家可以自定义一个宏定义,来做日志输出。
#ifdef DEBUG
#define DDLOG(…) printf(” %s\n”,[[NSString stringWithFormat:VA_ARGS]UTF8String]);
#define DDLOG_CURRENT_METHOD NSLog(@”%@-%@”, NSStringFromClass([self class]), NSStringFromSelector(_cmd))
#else
#define DDLOG(…) ;
#define DDLOG_CURRENT_METHOD ;
#endif
字体适配的问题
ios 9 之前的lab 字体可以显示全,但是到了ios10 发觉字体显示不全了.得适配啊.app 会跟随手机系统字体大小而改变了.
简单粗暴地方法就是不让他跟着手机系统的字体改变而改变.
myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline];
// UIFont 的preferredFontForTextStyle: 意思是指定一个样式,并让字体大小符合用户设定的字体大小。
/*
Indicates whether the corresponding element should automatically update its font when the device’s UIContentSizeCategory is changed.
For this property to take effect, the element’s font must be a font vended using +preferredFontForTextStyle: or +preferredFontForTextStyle:compatibleWithTraitCollection: with a valid UIFontTextStyle.
*/
//是否更新字体的变化
label.adjustsFontForContentSizeCategory = YES;
字体变大,原有frame需要适配
发现程序内Label标签原来2个字的宽度是24,现在2个字需要27的宽度来显示了。。
iOS 10 开始的通知
1.所有相关通知被统一到了UserNotifications.framework框架中。
2.增加了撤销、更新、中途还可以修改通知的内容。
3.通知不在是简单的文本了,可以加入视频、图片,自定义通知的展示等等。
4.iOS 10相对之前的通知来说更加好用易于管理,并且进行了大规模优化,对于开发者来说是一件好事。
5.iOS 10开始对于权限问题进行了优化,申请权限就比较简单了(本地与远程通知集成在一个方法中)。
所有的推送平台,不管是极光还是什么的,要想收到推送,这个是必须打开的
Image may be NSFW.
Clik here to view.
- (void)userNotificationCenter:(UNUserNotificationCenter )center willPresentNotification:(UNNotification )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
//应用在前台收到通知 NSLog(@”========%@”, notification);
}
推送的代理iOS10收到通知不再是在[application: didReceiveRemoteNotification:]方法去处理, iOS10推出新的代理方法,接收和处理各类通知(本地或者远程) (void)userNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)())completionHandler {
//点击通知进入应用 NSLog(@”response:%@”, response);
}
xcode8的注释快捷键注释不能用了, command+/ 不行了
解决办法:
因为苹果解决xcode ghost。把插件屏蔽了。解决方法
命令运行: sudo /usr/libexec/xpccachectl
然后必须重启电脑后生效
Image may be NSFW.
Clik here to view.
颜色问题, iOS 10 苹果官方建议我们使用sRGB,因为它性能更好,色彩更丰富。
UIColor类中新增了两个Api如下:
+ (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
- (UIColor *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
判断版本问题
判断系统版本是我们经常用到的,尤其是现在大家都有可能需要适配iOS 10,那么问题就出现了,如下图:
我们得到了答案是:
//值为 1
[[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue]
//值为10.000000
[[UIDevice currentDevice] systemVersion].floatValue,
//值为10.0
[[UIDevice currentDevice] systemVersion]
所以说判断系统方法最好还是用后面的两种方法,哦~我忘记说了[[UIDevice currentDevice] systemVersion].floatValue这个方法也是不靠谱的,好像在8.3版本输出的值是8.2,记不清楚了反正是不靠谱的,所以建议大家用[[UIDevice currentDevice] systemVersion]这个方法!
Swift判断如下:
if #available(iOS 10.0, *) {
print(“iOS 10.0”); // iOS 10.0啊
} else{ };
https的问题
iOS 9中默认非HTTS的网络是被禁止的,当然我们也可以把NSAllowsArbitraryLoads设置为YES禁用ATS。不过iOS 10从2017年1月1日起苹果不允许我们通过这个方法跳过ATS,也就是说强制我们用HTTPS,如果不这样的话提交App可能会被拒绝。但是我们可以通过NSExceptionDomains来针对特定的域名开放HTTP可以容易通过审核。
隐私权限
iOS 10 开始对隐私权限更加严格,如果你不设置就会直接崩溃,现在很多遇到崩溃问题了,一般解决办法都是在info.plist文件添加对应的Key-Value就可以了。
Image may be NSFW.
Clik here to view.
NSPhotoLibraryUsageDescription
App需要您的同意,才能访问相册
NSCameraUsageDescription
App需要您的同意,才能访问相机
NSMicrophoneUsageDescription
App需要您的同意,才能访问麦克风
NSLocationUsageDescription
App需要您的同意,才能访问位置
NSLocationWhenInUseUsageDescription
App需要您的同意,才能在使用期间访问位置
NSLocationAlwaysUsageDescription
App需要您的同意,才能始终访问位置
NSCalendarsUsageDescription
App需要您的同意,才能访问日历
NSRemindersUsageDescription
App需要您的同意,才能访问提醒事项
NSMotionUsageDescription App需要您的同意,才能访问运动与健身
NSHealthUpdateUsageDescription
App需要您的同意,才能访问健康更新
NSHealthShareUsageDescription
App需要您的同意,才能访问健康分享
NSBluetoothPeripheralUsageDescription
App需要您的同意,才能访问蓝牙
NSAppleMusicUsageDescription
App需要您的同意,才能访问媒体资料库
权限以及相关设置
iOS10调用相册会Crash下面信息:
This app has crashed because it attempted to access privacy-sensitive data without a usage description.
The app’s Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
大体意思就是这个App缺少一个获取私有(敏感)数据的权限描述,需要我们在info.plist文件中必须含有一个名字叫做NSPhotoLibraryUsageDescription的值来解释为什么应用需要使用这个数据,没错,获取相册资源的键值就是NSPhotoLibraryUsageDescription
去plist文件中添加了下面的键值:
Image may be NSFW.
Clik here to view.
再点击获取图片资源,就弹出了一个获取权限的问候,不会发生崩溃了:
Image may be NSFW.
Clik here to view.
Privacy - Microphone Usage Description //麦克风权限
Privacy - Contacts Usage Description //通讯录权限
Privacy - Camera Usage Description //摄像头权限
Privacy - NSSiriUsageDescription //Siri的权限
Privacy - Bluetooth Peripheral Usage Description //蓝牙
Privacy - Reminders Usage Description //提醒事项
Privacy - Motion Usage Description //运动与健康
Privacy - Media Libaray Usage Description //媒体资源库
Privacy - Calendars Usage Description //日历
xib设定好固定尺寸在代码中获取控件尺寸都变成(0,0,1000,1000)
UIView中要从- (void)updateConstraints或者- (void)drawRect:(CGRect)rect获取控件尺寸。
(void)updateConstraints
{
[super updateConstraints];
}(void)drawRect:(CGRect)rect
{
[super drawRect:rect];
}
UIViewController中要从- (void)viewDidLayoutSubviews获取控件尺寸。(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
}
Xcode 8使用Xib awakeFromNib的警告问题
在Xcode 8之前我们使用Xib初始化- (void)awakeFromNib {}都是这么写也没什么问题,但是在Xcode 8会有如下警告:
Image may be NSFW.
Clik here to view.
如果不喜欢这个警告的话,应该明确的加上[super awakeFromNib];我们来看看官方说明:
隐藏状态栏的功能坏掉:
升级到 iOS 10.0后,在查看全屏图片的时候,需要在 Present 之前给要 present 的 view controller 设置 modalPresentationCapturesStatusBarAppearance = true。然后就好啦
TestViewController *testVC = [[TestViewController alloc] init];
testVC.modalPresentationCapturesStatusBarAppearance = true;
[self presentViewController:testVC animated:YES completion:nil];
//iOS 10 状态栏的设置
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
************iOS 10 UITextContentType
// The textContentType property is to provide the keyboard with extra information about the semantic intent of the text document.
@property(nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil
在iOS 10 UITextField添加了textContentType枚举,指示文本输入区域所期望的语义意义。
使用此属性可以给键盘和系统信息,关于用户输入的内容的预期的语义意义。例如,您可以指定一个文本字段,用户填写收到一封电子邮件确认 uitextcontenttypeemailaddress。当您提供有关您期望用户在文本输入区域中输入的内容的信息时,系统可以在某些情况下自动选 择适当的键盘,并提高键盘修正和主动与其他文本输入机会的整合。
UIScrollView自带刷新功能
Image may be NSFW.
Clik here to view.
iOS 10 以后只要是继承UIScrollView那么就支持刷新功能:
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;
ImagePickerController.cameraViewTransform问题
(本条更新于:2016-09-21) 很多人反映自定义相机出现了问题,cameraViewTransform不能用了,其实网上关于这个的资料不是很多,在这里提供参考办法如下:
通过监听AVCaptureSessionDidStartRunningNotification来解决
//#import