您的位置:首页 > 产品设计 > UI/UE

iOS10适配系列ATS、隐私数据、UserNotifications、UICollectionView汇总

2016-09-20 19:23 399 查看
随着iOS10已经发布,大家的App都需要适配iOS10,下面是我总结的一些关于iOS10适配方面的问题,如果有错误,欢迎指出.

1.系统判断方法失效:

在你的项目中,当需要判断系统版本的话,不要使用下面的方法:

<code class="cpp"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:<span class="hljs-number">1</span>] intValue]>=<span class="hljs-number">10</span>)</span></code>

它会永远返回
NO
,
substringToIndex:1
iOS 10 会被检测成 iOS 1了,

应该使用下面的这些方法:

Objective-C 中这样写:

<code class="lisp">#define SYSTEM_VERSION_EQUAL_TO<span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">v</span>)</span> <span class="hljs-list">([[[UIDevice currentDevice] systemVersion] compare<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:v</span> options<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:NSNumericSearch</span>] == NSOrderedSame)</span>
#define SYSTEM_VERSION_GREATER_THAN<span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">v</span>)</span> <span class="hljs-list">([[[UIDevice currentDevice] systemVersion] compare<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:v</span> options<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:NSNumericSearch</span>] == NSOrderedDescending)</span>
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO<span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">v</span>)</span> <span class="hljs-list">([[[UIDevice currentDevice] systemVersion] compare<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:v</span> options<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:NSNumericSearch</span>] != NSOrderedAscending)</span>
#define SYSTEM_VERSION_LESS_THAN<span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">v</span>)</span> <span class="hljs-list">([[[UIDevice currentDevice] systemVersion] compare<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:v</span> options<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:NSNumericSearch</span>] == NSOrderedAscending)</span>
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO<span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">v</span>)</span> <span class="hljs-list">([[[UIDevice currentDevice] systemVersion] compare<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:v</span> options<span class="hljs-keyword" style="color: rgb(0, 0, 136);">:NSNumericSearch</span>] != NSOrderedDescending)</span></code>

或者使用:

<code class="objectivec"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">if</span> ([[<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSProcessInfo</span> processInfo] isOperatingSystemAtLeastVersion:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSOperatingSystemVersion</span>){<span class="hljs-variable" style="color: rgb(102, 0, 102);">.majorVersion</span> = <span class="hljs-number" style="color: rgb(0, 102, 102);">9</span>, <span class="hljs-variable" style="color: rgb(102, 0, 102);">.minorVersion</span> = <span class="hljs-number" style="color: rgb(0, 102, 102);">1</span>, <span class="hljs-variable" style="color: rgb(102, 0, 102);">.patchVersion</span> = <span class="hljs-number" style="color: rgb(0, 102, 102);">0</span>}]) { <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSLog</span>(<span class="hljs-string" style="color: rgb(0, 136, 0);">@"Hello from > iOS 9.1"</span>);}
<span class="hljs-keyword" style="color: rgb(0, 0, 136);">if</span> ([<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSProcessInfo</span><span class="hljs-variable" style="color: rgb(102, 0, 102);">.processInfo</span> isOperatingSystemAtLeastVersion:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSOperatingSystemVersion</span>){<span class="hljs-number" style="color: rgb(0, 102, 102);">9</span>,<span class="hljs-number" style="color: rgb(0, 102, 102);">3</span>,<span class="hljs-number" style="color: rgb(0, 102, 102);">0</span>}]) { <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSLog</span>(<span class="hljs-string" style="color: rgb(0, 136, 0);">@"Hello from > iOS 9.3"</span>);}</code>

或者使用:

<code class="ruby"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">if</span> (<span class="hljs-constant">NSFoundationVersionNumber</span> > <span class="hljs-constant">NSFoundationVersionNumber_iOS_9_0</span>) { <span class="hljs-regexp" style="color: rgb(0, 136, 0);">//</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">do</span> stuff <span class="hljs-keyword" style="color: rgb(0, 0, 136);">for</span> iOS <span class="hljs-number" style="color: rgb(0, 102, 102);">9</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">and</span> newer} <span class="hljs-keyword" style="color: rgb(0, 0, 136);">else</span> { <span class="hljs-regexp" style="color: rgb(0, 136, 0);">//</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">do</span> stuff <span class="hljs-keyword" style="color: rgb(0, 0, 136);">for</span> older versions than iOS <span class="hljs-number" style="color: rgb(0, 102, 102);">9</span>}</code>

有时候会缺少一些常量,
NSFoundationVersionNumber
是在
NSObjCRuntime.h
中定义的,作为Xcode7.3.1的一部分,我们设定常熟范围从iPhone OS 2到
#define NSFoundationVersionNumber_iOS_8_4 1144.17
,在iOS 10(Xcode 8)中,苹果补充了缺少的数字,设置有未来的版本.

<code class="cpp"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_0 <span class="hljs-number">1240.1</span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_1 <span class="hljs-number">1241.14</span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_2 <span class="hljs-number">1242.12</span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_3 <span class="hljs-number">1242.12</span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_4 <span class="hljs-number">1280.25</span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#<span class="hljs-keyword">define</span> NSFoundationVersionNumber_iOS_9_x_Max <span class="hljs-number">1299</span></span></code>

Swift中这样写:

<code class="cpp"><span class="hljs-function"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">if</span> <span class="hljs-title">NSProcessInfo</span><span class="hljs-params" style="color: rgb(102, 0, 102);">()</span>.<span class="hljs-title">isOperatingSystemAtLeastVersion</span><span class="hljs-params" style="color: rgb(102, 0, 102);">(NSOperatingSystemVersion(majorVersion: <span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>, minorVersion: <span class="hljs-number" style="color: rgb(0, 102, 102);">0</span>, patchVersion: <span class="hljs-number" style="color: rgb(0, 102, 102);">0</span>)</span>) </span>{
<span class="hljs-comment" style="color: rgb(136, 0, 0);">// 代码块</span>
}</code>

或者使用
<code class="cpp"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">if</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#available(iOS <span class="hljs-number">10.0</span>, *) { </span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);">// 代码块</span>
} <span class="hljs-keyword" style="color: rgb(0, 0, 136);">else</span> {
<span class="hljs-comment" style="color: rgb(136, 0, 0);">// 代码块</span>
}</code>

2.隐私数据访问问题:

你的项目中访问了隐私数据,比如:相机,相册,联系人等,在Xcode8中打开编译的话,统统会crash,控制台会输出下面这样的日志:



Snip20160905_1.png

这是因为iOS对用户的安全和隐私的增强,在申请很多私有权限的时候都需要添加描述,但是,在使用Xcode 8之前的Xcode还是使用系统的权限通知框.

要想解决这个问题,只需要在
info.plist
添加
NSContactsUsageDescription
的key, value自己随意填写就可以,这里列举出对应的key(Source Code模式下):
<code class="xml"><span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 相册 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSPhotoLibraryUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问相册<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 相机 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSCameraUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问相机<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 麦克风 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSMicrophoneUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问麦克风<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 位置 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSLocationUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问位置<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 在使用期间访问位置 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSLocationWhenInUseUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能在使用期间访问位置<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 始终访问位置 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSLocationAlwaysUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能始终访问位置<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 日历 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSCalendarsUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问日历<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 提醒事项 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSRemindersUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问提醒事项<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 运动与健身 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSMotionUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span> <span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问运动与健身<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 健康更新 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSHealthUpdateUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问健康更新 <span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 健康分享 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSHealthShareUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问健康分享<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 蓝牙 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSBluetoothPeripheralUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问蓝牙<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 媒体资料库 --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSAppleMusicUsageDescription<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>App需要您的同意,才能访问媒体资料库<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span></code>

如果不起作用,可以请求后台权限,类似于这样:
<code class="xml"><span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>UIBackgroundModes<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">array</span>></span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);"><!-- 在这里写上你在后台模式下要使用权限对应的key --></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>location<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
...
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">array</span>></span></code>

或者在Xcode里选中当前的
target
,选择
Capabilities
,找到
Background Modes
,打开它,在里面选择对应权限



后台模式的操作.png

3.UIColor的问题

官方文档中说:大多数
core
开头的图形框架和
AVFoundation
都提高了对扩展像素和宽色域色彩空间的支持.通过图形堆栈扩展这种方式比以往支持广色域的显示设备更加容易。现在对UIKit扩展可以在sRGB的色彩空间下工作,性能更好,也可以在更广泛的色域来搭配sRGB颜色.如果你的项目中是通过低级别的api自己实现图形处理的,建议使用sRGB,也就是说在项目中使用了RGB转化颜色的建议转换为使用sRGB,在
UIColor
类中新增了两个api:

<code class="objectivec">- (<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIColor</span> *)initWithDisplayP3Red:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)displayP3Red green:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)green blue:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)blue alpha:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)alpha <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
+ (<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIColor</span> *)colorWithDisplayP3Red:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)displayP3Red green:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)green blue:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)blue alpha:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">CGFloat</span>)alpha <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);</code>

4.真彩色的显示

真彩色的显示会根据光感应器来自动的调节达到特定环境下显示与性能的平衡效果,如果需要这个功能的话,可以在
info.plist
里配置(在Source Code模式下):

<code class="xml"><span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>UIWhitePointAdaptivityStyle<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span></code>

它有五种取值,分别是:

<code class="cs"><<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>>UIWhitePointAdaptivityStyleStandard</<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>> <span class="hljs-comment" style="color: rgb(136, 0, 0);">// 标准模式</span>
<<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>>UIWhitePointAdaptivityStyleReading</<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>> <span class="hljs-comment" style="color: rgb(136, 0, 0);">// 阅读模式</span>
<<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>>UIWhitePointAdaptivityStylePhoto</<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>> <span class="hljs-comment" style="color: rgb(136, 0, 0);">// 图片模式</span>
<<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>>UIWhitePointAdaptivityStyleVideo</<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>> <span class="hljs-comment" style="color: rgb(136, 0, 0);">// 视频模式</span>
<<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>>UIWhitePointAdaptivityStyleStandard</<span class="hljs-keyword" style="color: rgb(0, 0, 136);">string</span>> <span class="hljs-comment" style="color: rgb(136, 0, 0);">// 游戏模式</span></code>

也就是说如果你的项目是阅读类的,就选择
UIWhitePointAdaptivityStyleReading
这个模式,五种模式的显示效果是从上往下递减,也就是说如果你的项目是图片处理类的,你选择的是阅读模式,给选择太好的效果会影响性能.

5.ATS的问题

1.在iOS 9的时候,默认非HTTS的网络是被禁止的,我们可以在
info.plist
文件中添加
NSAppTransportSecurity
字典,将
NSAllowsArbitraryLoads
设置为
YES
来禁用ATS;

2.从2017年1月1日起,,所有新提交的 app 默认不允许使用
NSAllowsArbitraryLoads
来绕过ATS的限制,默认情况下你的 app 可以访问加密足够强的(TLS V1.2以上)HTTPS内容;

3.可以选择使用
NSExceptionDomains
设置白名单的方式对特定的域名开放HTTP内容来通过审核,比如说你的应用集成了第三方的登录分享SDK,可以通过这种方式来做,下面以新浪SDK作为示范(Source Code 模式下):

<code class="xml"> <span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSAppTransportSecurity<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSExceptionDomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>sina.cn<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>weibo.cn<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>weibo. com<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>sinaimg.cn<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>sinajs.cn<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>sina.com.cn<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionMinimumTLSVersion<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>TLSv1.0<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">string</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSThirdPartyExceptionRequiresForwardSecrecy<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">false</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>NSIncludesSubdomains<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">key</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"><<span class="hljs-title" style="color: rgb(0, 0, 136);">true</span>/></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102);"></<span class="hljs-title" style="color: rgb(0, 0, 136);">dict</span>></span></code>

4.在iOS 10 中
info.plist
文件新加入了
NSAllowsArbitraryLoadsInWebContent
键,允许任意web页面加载,同时苹果会用 ATS 来保护你的app;

5.安全传输不再支持
SSLv3
, 建议尽快停用
SHA1
3DES
算法;

6.UIStatusBar的问题:

在iOS10中,如果还使用以前设置UIStatusBar类型或者控制隐藏还是显示的方法,会报警告,方法过期,如下图:



UIStatusBar的警告.png

上面方法到 iOS 10 不能使用了,要想修改UIStatusBar的样式或者状态使用下图中所示的属性或方法:

<code class="objectivec"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">@property</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">nonatomic</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136);">readonly</span>) <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIStatusBarStyle</span> preferredStatusBarStyle <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">7</span>_0) __TVOS_PROHIBITED; <span class="hljs-comment" style="color: rgb(136, 0, 0);">// Defaults to UIStatusBarStyleDefault</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136);">@property</span>(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">nonatomic</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136);">readonly</span>) <span class="hljs-built_in" style="color: rgb(102, 0, 102);">BOOL</span> prefersStatusBarHidden <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">7</span>_0) __TVOS_PROHIBITED; <span class="hljs-comment" style="color: rgb(136, 0, 0);">// Defaults to NO</span>
- (<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIStatusBarStyle</span>)preferredStatusBarStyle <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">7</span>_0) __TVOS_PROHIBITED; <span class="hljs-comment" style="color: rgb(136, 0, 0);">// Defaults to UIStatusBarStyleDefault</span>
- (<span class="hljs-built_in" style="color: rgb(102, 0, 102);">BOOL</span>)prefersStatusBarHidden <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">7</span>_0) __TVOS_PROHIBITED; <span class="hljs-comment" style="color: rgb(136, 0, 0);">// Defaults to NO</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0);">// 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.</span>
- (<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIStatusBarAnimation</span>)preferredStatusBarUpdateAnimation <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">7</span>_0) __TVOS_PROHIBITED; <span class="hljs-comment" style="color: rgb(136, 0, 0);">// Defaults to UIStatusBarAnimationFade</span></code>

7.UITextField

在iOS 10 中,
UITextField
新增了
textContentType
字段,是
UITextContentType
类型,它是一个枚举,作用是可以指定输入框的类型,以便系统可以分析出用户的语义.是电话类型就建议一些电话,是地址类型就建议一些地址.可以在
#import <UIKit/UITextInputTraits.h>
文件中,查看
textContentType
字段,有以下可以选择的类型:

<code class="objectivec"><span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeName</span>                      <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeNamePrefix</span>                <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeGivenName</span>                 <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeMiddleName</span>                <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeFamilyName</span>                <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeNameSuffix</span>                <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeNickname</span>                  <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeJobTitle</span>                  <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeOrganizationName</span>          <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeLocation</span>                  <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeFullStreetAddress</span>         <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeStreetAddressLine1</span>        <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeStreetAddressLine2</span>        <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeAddressCity</span>               <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeAddressState</span>              <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeAddressCityAndState</span>       <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeSublocality</span>               <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeCountryName</span>               <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypePostalCode</span>                <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeTelephoneNumber</span>           <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeEmailAddress</span>              <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeURL</span>                       <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);
<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIKIT_EXTERN</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentType</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136);">const</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102);">UITextContentTypeCreditCardNumber</span>          <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);</code>

8.UserNotifications(用户通知)

iOS 10 中将通知相关的 API 都统一了,在此基础上很多用户定义的通知,并且可以捕捉到各个通知状态的回调.以前通知的概念是:大家想接受的提前做好准备,然后一下全两分发,没收到也不管了,也不关心发送者,现在的用户通知做成了类似于网络请求,先发一个
request
得到
response
的流程,还封装了
error
,可以在各个状态的方法中做一些额外的操作,并且能获得一些字段,比如发送者之类的.这个功能的头文件是:
#import
<UserNotifications/UserNotifications.h>


主要有以下文件:

<code class="objectivec"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/NSString+UserNotifications.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNError.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotification.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationAction.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationAttachment.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationCategory.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationContent.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationRequest.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationResponse.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationSettings.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationSound.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationTrigger.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNUserNotificationCenter.h></span></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68);">#import <span class="hljs-title"><UserNotifications/UNNotificationServiceExtension.h></span></span></code>

9.UICollectionViewCell的的优化

在iOS 10 之前,UICollectionView上面如果有大量cell,当用户活动很快的时候,整个UICollectionView的卡顿会很明显,为什么会造成这样的问题,这里涉及到了iOS 系统的重用机制,当cell准备加载进屏幕的时候,整个cell都已经加载完成,等待在屏幕外面了,也就是整整一行cell都已经加载完毕,这就是造成卡顿的主要原因,专业术语叫做:掉帧.

要想让用户感觉不到卡顿,我们的app必须帧率达到60帧/秒,也就是说每帧16毫秒要刷新一次.
iOS 10 之前UICollectionViewCell的生命周期是这样的:
1.用户滑动屏幕,屏幕外有一个cell准备加载进来,把cell从reusr队列拿出来,然后调用
prepareForReuse
方法,在这个方法里面,可以重置cell的状态,加载新的数据;
2.继续滑动,就会调用
cellForItemAtIndexPath
方法,在这个方法里面给cell赋值模型,然后返回给系统;
3.当cell马上进去屏幕的时候,就会调用
willDisplayCell
方法,在这个方法里面我们还可以修改cell,为进入屏幕做最后的准备工作;
4.执行完
willDisplayCell
方法后,cell就进去屏幕了.当cell完全离开屏幕以后,会调用
didEndDisplayingCell
方法.
iOS 10 UICollectionViewCell的生命周期是这样的:
1.用户滑动屏幕,屏幕外有一个cell准备加载进来,把cell从reusr队列拿出来,然后调用
prepareForReuse
方法,在这里当cell还没有进去屏幕的时候,就已经提前调用这个方法了,对比之前的区别是之前是cell的上边缘马上进去屏幕的时候就会调用该方法,而iOS 10 提前到cell还在屏幕外面的时候就调用;
2.在
cellForItemAtIndexPath
中创建cell,填充数据,刷新状态等操作,相比于之前也提前了;
3.用户继续滑动的话,当cell马上就需要显示的时候我们再调用
willDisplayCell
方法,原则就是:何时需要显示,何时再去调用
willDisplayCell
方法;
4.当cell完全离开屏幕以后,会调用
didEndDisplayingCell
方法,跟之前一样,cell会进入重用队列.

在iOS 10 之前,cell只能从重用队列里面取出,再走一遍生命周期,并调用
cellForItemAtIndexPath
创建或者生成一个cell.

在iOS 10 中,系统会cell保存一段时间,也就是说当用户把cell滑出屏幕以后,如果又滑动回来,cell不用再走一遍生命周期了,只需要调用
willDisplayCell
方法就可以重新出现在屏幕中了.

iOS 10 中,系统是一个一个加载cell的,二以前是一行一行加载的,这样就可以提升很多性能;
iOS 10 新增加的Pre-Fetching预加载
这个是为了降低UICollectionViewCell在加载的时候所花费的时间,在 iOS 10 中,除了数据源协议和代理协议外,新增加了一个
UICollectionViewDataSourcePrefetching
协议,这个协议里面定义了两个方法:
<code class="objectivec">- (<span class="hljs-keyword" style="color: rgb(0, 0, 136);">void</span>)collectionView:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UICollectionView</span> *)collectionView prefetchItemsAtIndexPaths:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSArray</span><<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSIndexPath</span> *> *)indexPaths <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);

- (<span class="hljs-keyword" style="color: rgb(0, 0, 136);">void</span>)collectionView:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UICollectionView</span> *)collectionView cancelPrefetchingForItemsAtIndexPaths:(<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSArray</span><<span class="hljs-built_in" style="color: rgb(102, 0, 102);">NSIndexPath</span> *> *)indexPaths  <span class="hljs-built_in" style="color: rgb(102, 0, 102);">NS_AVAILABLE_IOS</span>(<span class="hljs-number" style="color: rgb(0, 102, 102);">10</span>_0);</code>

ColletionView prefetchItemsAt indexPaths
这个方法是异步预加载数据的,当中的
indexPaths
数组是有序的,就是item接收数据的顺序;
CollectionView cancelPrefetcingForItemsAt indexPaths
这个方法是可选的,可以用来处理在滑动中取消或者降低提前加载数据的优先级.

注意:这个协议并不能代替之前读取数据的方法,仅仅是辅助加载数据.

Pre-Fetching预加载对UITableViewCell同样适用.

10. UIRefreshControl的使用

在iOS 10 中, UIRefreshControl可以直接在UICollectionView和UITableView中使用,并且脱离了UITableViewController.现在RefreshControl是UIScrollView的一个属性.

使用方法:
<code class="objectivec"><span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIRefreshControl</span> *refreshControl = [[<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIRefreshControl</span> alloc] init];
[refreshControl addTarget:<span class="hljs-keyword" style="color: rgb(0, 0, 136);">self</span> action:<span class="hljs-keyword" style="color: rgb(0, 0, 136);">@selector</span>(loadData) forControlEvents:<span class="hljs-built_in" style="color: rgb(102, 0, 102);">UIControlEventValueChanged</span>];
collectionView<span class="hljs-variable" style="color: rgb(102, 0, 102);">.refreshControl</span> = refreshControl;</code>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: