iOS 10 与Xcode 8 新特性

iOS 10


1. 访问权限崩溃问题

如果打开APP后点击有关权限访问后直接Crash了则需要在需要在info.plist文件中进行相关配置(蓝牙,日历,相机,相册,相机,联系人,健康等权限...)

权限配置步骤:

  1. 打开项目中的info.plist文件
  2. 在info.plist文件Add Row一行后选择相应的权限进行添加
  3. 先去相应的Key,Value 应该可以随便填写
配置地方

如果一个个添加嫌麻烦可以全部添加到plist文件中



打开plist源文件后添加如

<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string> 
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSHomeKitUsageDescription</key>
<string>App需要您的同意,才能访问家庭 </string>
<key>NSContactsUsageDescription</key>
<string>App需要您的同意,才能访问通讯录 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSAppleMusicUsageDescription</key> 
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSMicrophoneUsageDescription</key>    
<string>App需要您的同意,才能访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSRemindersUsageDescription</key>   
<string>App需要您的同意,才能访问提醒事项</string>
<key>NSSiriUsageDescription</key>
<string>App需要您的同意,才能访问Siri</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>App需要您的同意,才能访问语音识别</string>
<key>NSVideoSubscriberAccountUsageDescription</key>
<string>App需要您的同意,才能访问视频用户账户</string>```

#2. nullable报错问题
使用Xcode8之后,需要删除nullable否则报错

-(void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error```

3. ATS(App Transport Security) 网络适配问题

  1. iOS 9时,默认HTTS的网络是被禁止的, 但可以通过向info.plist文件中添加NSAppTransportSecurity,并将NSAllowsArbitraryLoads设置为YES来禁用ATS。但是,从2017年1月1日起,所有新提交的APP默认不允许配置NSAllowsArbitraryLoads来绕过ATS的限制,所以你的APP应尽早使用HTTPS进行内容访问,以避免APP被拒绝风险。
  2. 如果APP中如果集成了第三方的SDK,则可以通过NSAppTransportSecurity中NSExceptionDomains设置白名单的方式对特定的域名开放HTTP内容来通过审核。
    NSExceptionDomains设置方法
  3. 在NSAppTransportSecurity 中新加入了NSAllowsArbitraryLoadsInWebContent键,允许任意web页面加载,同时苹果会用 ATS 来保护你的app。

4.新增UIViewPropertyAnimator类

类特点:

1.可中断性
2.可擦除
3.可反转性
4.丰富的动画时间控制功能

//初始化属性动画器
UIViewPropertyAnimator *viewPropertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:5.f curve:UIViewAnimationCurveLinear animations:^{
    [self.view setAlpha:0.3];
}];
[viewPropertyAnimator startAnimation];

5.Notification(通知)

  • 所有相关通知被统一到了UserNotifications.framework框架中。
  • 增加了撤销、更新、中途还可以修改通知的内容。
  • 通知中可以加入视频、图片,自定义通知的展示等等。
  • 相对之前的通知来说更加好用易于管理,并且进行了大规模优化。
  • 对于权限问题进行了优化,申请权限就比较简单了(本地与远程通知集成在一个方法中)。
    通知相关参考

6.UIStatusBar方法过期

过期方法:

// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;```
新方法:

if UIKIT_DEFINE_AS_PROPERTIES

@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault
@property(nonatomic, readonly) BOOL prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO
// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
@property(nonatomic, readonly) UIStatusBarAnimation preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarAnimationFade

else

  • (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault
  • (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to NO
    // Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
  • (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarAnimationFade

endif```

上面这个新方法在UIViewController.h文件中,只需要在viewController里调用即可。

- (BOOL)prefersStatusBarHidden{ 
  return YES;
}

- (UIStatusBarStyle)preferredStatusBarStyle{  
  return UIStatusBarStyleDefault;
}```

##7.插件取消
Xcode8取消了三方插件的功能,好多教程破解可以继续使用,但是可能app上线可能会被拒。

#Xcode 8 
---
Xcode 8 可以创建iPhone,iPad,Apple Watch,Mac,Apple TV 等平台的应用程序。

![Xcode 8 首界面](http://upload-images.jianshu.io/upload_images/2529977-c4a3f37cef2c061e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##1. Swift 3
Swift 3对大量语法进行了优化及更新,会对Swift 3以前的版本会有影响,为解决此问题Xcode 8在编译设置中支持开发者选择Swift 2或Swift 2.3 进行编译。
如果一个目标(Target)需要支持Swift 2.3, 需要在目标(Target)的编译设置里把Use Legacy Swift Language Version 设置成Yes
![支持Swift语言以往版本](http://upload-images.jianshu.io/upload_images/2529977-6b613df856043023.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##2. 证书管理
Xcode 8添加了自动管理证书功能。
建议勾选这个选项Automatically manage signing
如未设置开发者账号,则需要在xcode->preferences->Accounts中添加

![自动管理证书](http://upload-images.jianshu.io/upload_images/2529977-81d200dcecac3fa6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


#Xcode 8问题解决
---
##1. 代码注释快捷功能不能使用
解决方法
打开终端 - 输入命令运行:sudo /usr/libexec/xpccachectl
重启计算机

##2. 出现杂乱的Debug
会在Debug窗口出现如下信息
>2016-10-10 16:12:37.746003 HHRouterExample[9121:339626] 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, privacy_setting: 2, enable_private_data: 0

屏蔽方法
选择Product-> Scheme -> Edit Scheme -> Run -> Arguments 然后在Environment Variables里添加`OS_ACTIVITY_MODE = Disable`
![屏蔽方法](http://upload-images.jianshu.io/upload_images/2529977-df319775614e7154.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##官方链接地址
---
[UserNotifications](https://developer.apple.com/reference/usernotifications)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335

推荐阅读更多精彩内容

  • 因为要结局swift3.0中引用snapKit的问题,看到一篇介绍Xcode8,swift3变化的文章,觉得很详细...
    uniapp阅读 4,367评论 0 12
  • iOS6新特性 一、关于内存警告 ios6中废除了viewDidUnload,viewWillUnload这两个系...
    Jimmy_P阅读 2,127评论 3 29
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 11,952评论 4 60
  • 今天我们上了主题为“节日”的班会,达成一个共识:无论是中国的还是外国的节日,无论它的由来是什么,无论是怎样的庆祝方...
    常星慧阅读 231评论 0 0
  • 1. 以前的一个学生A,毕业前找了一个单位实习,干了不到一个月辞职了,她来找我的时候,还带着一脸愤愤不平的表情。 ...
    不辣的妈阅读 323评论 0 2