看各個大神整理而成
1、檢查版本問題
不可以像下面這樣用
#define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1]intValue]>=10)
這樣可以
[[UIDevice currentDevice].systemVersion floatValue] >= 10.0
2、隱私設置
你的項目中訪問了隱私數據,比如:相機,相冊,聯系人等,在Xcode8中打開編譯的話,統統會crash
<!-- 相冊 --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能訪問相冊</string> <!-- 相機 --> <key>NSCameraUsageDescription</key> <string>App需要您的同意,才能訪問相機</string> <!-- 麥克風 --> <key>NSMicrophoneUsageDescription</key> <string>App需要您的同意,才能訪問麥克風</string> <!-- 位置 --> <key>NSLocationUsageDescription</key> <string>App需要您的同意,才能訪問位置</string> <!-- 在使用期間訪問位置 --> <key>NSLocationWhenInUseUsageDescription</key> <string>App需要您的同意,才能在使用期間訪問位置</string> <!-- 始終訪問位置 --> <key>NSLocationAlwaysUsageDescription</key> <string>App需要您的同意,才能始終訪問位置</string> <!-- 日歷 --> <key>NSCalendarsUsageDescription</key> <string>App需要您的同意,才能訪問日歷</string> <!-- 提醒事項 --> <key>NSRemindersUsageDescription</key> <string>App需要您的同意,才能訪問提醒事項</string> <!-- 運動與健身 --> <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問運動與健身</string> <!-- 健康更新 --> <key>NSHealthUpdateUsageDescription</key> <string>App需要您的同意,才能訪問健康更新 </string> <!-- 健康分享 --> <key>NSHealthShareUsageDescription</key> <string>App需要您的同意,才能訪問健康分享</string> <!-- 藍牙 --> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能訪問藍牙</string> <!-- 媒體資料庫 --> <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能訪問媒體資料庫</string>
3、UIColor問題
官方文檔中說:大多數core
開頭的圖形框架和AVFoundation
都提高了對擴展像素和寬色域色彩空間的支持.通過圖形堆棧擴展這種方式比以往支持廣色域的顯示設備更加容易。現在對UIKit擴展可以在sRGB的色彩空間下工作,性能更好,也可以在更廣泛的色域來搭配sRGB顏色.如果你的項目中是通過低級別的api自己實現圖形處理的,建議使用sRGB,也就是說在項目中使用了RGB轉化顏色的建議轉換為使用sRGB,在UIColor
類中新增了兩個api:
- (UIColor *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0); + (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
4、真色彩顯示
真彩色的顯示會根據光感應器來自動的調節達到特定環境下顯示與性能的平衡效果,如果需要這個功能的話,可以在info.plist
里配置(在Source Code模式下):
<key>UIWhitePointAdaptivityStyle</key>
它有五種取值,分別是:
<string>UIWhitePointAdaptivityStyleStandard</string> // 標准模式 <string>UIWhitePointAdaptivityStyleReading</string> // 閱讀模式 <string>UIWhitePointAdaptivityStylePhoto</string> // 圖片模式 <string>UIWhitePointAdaptivityStyleVideo</string> // 視頻模式 <string>UIWhitePointAdaptivityStyleStandard</string> // 游戲模式
也就是說如果你的項目是閱讀類的,就選擇UIWhitePointAdaptivityStyleReading
這個模式,五種模式的顯示效果是從上往下遞減,也就是說如果你的項目是圖片處理類的,你選擇的是閱讀模式,給選擇太好的效果會影響性能.
5、ATS問題
---在iOS 9的時候,默認非HTTS的網絡是被禁止的,我們可以在info.plist
文件中添加NSAppTransportSecurity
字典,將NSAllowsArbitraryLoads
設置為YES
來禁用ATS;
---從2017年1月1日起,,所有新提交的 app 默認不允許使用NSAllowsArbitraryLoads
來繞過ATS的限制,默認情況下你的 app 可以訪問加密足夠強的(TLS V1.2以上)HTTPS內容;
---可以選擇使用NSExceptionDomains
設置白名單的方式對特定的域名開放HTTP內容來通過審核,比如說你的應用集成了第三方的登錄分享SDK,可以通過這種方式來做,下面以新浪SDK作為示范(Source Code 模式下):
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>sina.cn</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>weibo.cn</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>weibo. com</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>sinaimg.cn</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>sinajs.cn</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>sina.com.cn</key> <dict> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict>
---在iOS 10 中info.plist
文件新加入了NSAllowsArbitraryLoadsInWebContent
鍵,允許任意web頁面加載,同時蘋果會用 ATS 來保護你的app;
---安全傳輸不再支持SSLv3
, 建議盡快停用SHA1
和3DES
算法;
6、UIStatusBar
原來setStatusBarStyle不能用了,現在可以通過屬性來設置
@property(nonatomic,readonly)UIStatusBarStyle preferredStatusBarStyle
@property(nonatomic,readonly)BOOL prefersStatusBarHidden
-(BOOL)prefersStatusBarHidden
-(UIStatusBarAnimation)preferredStatusBarUpdateAnimation
7、UITextField
在iOS 10 中,UITextField
新增了textContentType
字段,是UITextContentType
類型,它是一個枚舉,作用是可以指定輸入框的類型,以便系統可以分析出用戶的語義.是電話類型就建議一些電話,是地址類型就建議一些地址.可以在#import <UIKit/UITextInputTraits.h>
文件中,查看textContentType
字段,有以下可以選擇的類型:
UITextContentTypeName UITextContentTypeNamePrefix UITextContentTypeGivenName UITextContentTypeMiddleName UITextContentTypeFamilyName UITextContentTypeNameSuffix UITextContentTypeNickname UITextContentTypeJobTitle UITextContentTypeOrganizationName UITextContentTypeLocation UITextContentTypeFullStreetAddress UITextContentTypeStreetAddressLine1 UITextContentTypeStreetAddressLine2 UITextContentTypeAddressCity UITextContentTypeAddressState UITextContentTypeAddressCityAndState UITextContentTypeSublocality UITextContentTypeCountryName UITextContentTypePostalCode UITextContentTypeTelephoneNumber UITextContentTypeEmailAddress UITextContentTypeURL UITextContentTypeCreditCardNumber
8、對UICollectionView進行了優化
對UICollectionView進行了優化,並新增加了預加載的UICollectionViewDataSourcePrefetching代理協議及代理方法
-(void)collectionView: (UICollectionView*)collectionView prefetchItemsAtIndexPaths: (NSArray*)indexPaths
-(void)collectionView: (UICollectionView*)collectionView cancelPrefetchingForItemsAtIndexPaths: (NSArray*)indexPaths
注意:這兩個代理方法並不能代替之前讀取數據的方法,僅僅是輔助加載數據在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的,二以前是一行一行加載的,這樣就可以提升很多性能;
9、UIRefreshControl
在iOS 10 中, UIRefreshControl可以直接在UICollectionView和UITableView中使用,並且脫離了UITableViewController.現在RefreshControl是UIScrollView的一個屬性.
使用方法:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(loadData) forControlEvents:UIControlEventValueChanged]; collectionView.refreshControl = refreshControl;
10、UserNotifications(用戶通知)
iOS 10 中將通知相關的 API 都統一了,在此基礎上很多用戶定義的通知,並且可以捕捉到各個通知狀態的回調.以前通知的概念是:大家想接受的提前做好准備,然后一下全兩分發,沒收到也不管了,也不關心發送者,現在的用戶通知做成了類似於網絡請求,先發一個request
得到response
的流程,還封裝了error
,可以在各個狀態的方法中做一些額外的操作,並且能獲得一些字段,比如發送者之類的.這個功能的頭文件是:#import <UserNotifications/UserNotifications.h>