18.iOS10新特性,適配教程,XCode8新特性

iOS 10 新特性

SiriKit

SiriKit的功能非常強(qiáng)大,支持音頻、視頻、消息發(fā)送接收、搜索照片、預(yù)訂行程、管理鍛煉等等。在用到此服務(wù)時(shí),siri會(huì)發(fā)送Intent對(duì)象,里面包括用戶的請(qǐng)求和各種數(shù)據(jù),可以對(duì)這個(gè)intent處理選擇適當(dāng)?shù)捻憫?yīng)。這個(gè)功能主要是看這兩個(gè)頭(<Intents/Intents.h><IntentsUI/IntentsUI.h>)

Proactive Suggestions 系統(tǒng)預(yù)先建議

背景就是iOS9的時(shí)候體統(tǒng)給予的主動(dòng)建議會(huì)通過:Spolight搜索,Safari搜索,Handoff,或者siri建議。在iOS10之后新增了,鍵盤QuickType建議,地圖,車載娛樂,應(yīng)用切換,siri交互,鎖屏播放。比如你正在一個(gè)應(yīng)用里看一個(gè)酒店,可以使用maoitem屬性保存正在查看的這個(gè)酒店的位置,然后你切換旅行或地圖App時(shí)這個(gè)位置可以自動(dòng)提供使用。如果你需要這樣利用系統(tǒng)來共享一個(gè)位置,那你需要指定這個(gè)位置的經(jīng)緯度,地名,電話等屬性來便于siri的直接調(diào)起。

User Notifications 用戶通知

總體的意思就是支持了很多用戶定義的通知,并且可以捕捉到各個(gè)通知狀態(tài)的回調(diào)。以往通知的概念是:大家想接收的都提前做好準(zhǔn)備,然后一下全量分發(fā),沒收到也不管了,也不關(guān)心發(fā)送者。現(xiàn)在用戶通知做成了和網(wǎng)絡(luò)請(qǐng)求有點(diǎn)像一個(gè)先發(fā)request再得到request的流程,甚至封裝了error,可以在各個(gè)狀態(tài)的方法中做一些額外操作,并且也能取到一些字段,如發(fā)送者等。這個(gè)功能的頭文件是:#import

#import <UserNotifications/NSString+UserNotifications.h>
#import <UserNotifications/UNError.h>
#import <UserNotifications/UNNotification.h>
#import <UserNotifications/UNNotificationAction.h>
#import <UserNotifications/UNNotificationAttachment.h>
#import <UserNotifications/UNNotificationCategory.h>
#import <UserNotifications/UNNotificationContent.h>
#import <UserNotifications/UNNotificationRequest.h>
#import <UserNotifications/UNNotificationResponse.h>
#import <UserNotifications/UNNotificationSettings.h>
#import <UserNotifications/UNNotificationSound.h>
#import <UserNotifications/UNNotificationTrigger.h>
#import <UserNotifications/UNUserNotificationCenter.h>
#import <UserNotifications/UNNotificationServiceExtension.h>

UITextField

在iOS10中,UITextField新增了textContentType字段,是UITextContentType類型,它是一個(gè)枚舉,作用是可以指定輸入框的類型,以便系統(tǒng)可以分析出用戶的語(yǔ)義。是電話類型就建議一些電話,是地址類型就建議一些地址,可以在#import

UIKIT_EXTERN UITextContentType const UITextContentTypeName                      NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeNamePrefix                NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeGivenName                 NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeMiddleName                NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeFamilyName                NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeNameSuffix                NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeNickname                  NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeJobTitle                  NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeOrganizationName          NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeLocation                  NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeFullStreetAddress         NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeStreetAddressLine1        NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeStreetAddressLine2        NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeAddressCity               NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeAddressState              NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeAddressCityAndState       NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeSublocality               NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeCountryName               NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypePostalCode                NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeTelephoneNumber           NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeEmailAddress              NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeURL                       NS_AVAILABLE_IOS(10_0);
UIKIT_EXTERN UITextContentType const UITextContentTypeCreditCardNumber

Integrating with the Messages App 與系統(tǒng)短信 app交互

對(duì)消息額支持很大,可以模擬發(fā)消息收消息,發(fā)郵件等,提供了UI界面。也提供了一些額外擴(kuò)展的api,如表情包區(qū)域。WWDC2016上說的各種消息內(nèi)的新操作在頭文件中都能找到Api。

Speech Recognition 語(yǔ)音識(shí)別轉(zhuǎn)文字

這個(gè)類里面的Api和方法調(diào)用都非常清晰,感覺使用起來會(huì)非常方便。

Wide Color 寬域顏色

文檔的原話說:大多數(shù)的core字打頭的圖形框架還有AVFoundation 都大大提高了對(duì)擴(kuò)展像素和寬色域色彩空間的支持。通過圖形堆棧擴(kuò)展這種方式比以往支持廣色域的顯示設(shè)備更加容易。現(xiàn)在對(duì)UIKit擴(kuò)展可以在sRGB的色彩空間下工作,性能更好,也可以在更廣泛的色域來搭配sRGB顏色。然后說了幾個(gè)場(chǎng)景說建議你用sRGB把,比如依賴于UIKit的clamp component values的應(yīng)用程序,或是使用較低級(jí)別api執(zhí)行自己圖像處理的都建議用sRGB吧。

然后看了下UIColor類里到底什么是sRGB?發(fā)現(xiàn)多了兩個(gè)iOS10新增的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);

細(xì)節(jié)都是一樣的就是一個(gè)類方法一個(gè)實(shí)例方法,我理解下,就是說建議你們以前改用colorwithRGB的地方新增都換成這個(gè)方法吧。可能大多數(shù)公司都抽成了RGB(a,g,b,a)這個(gè)宏吧,那就在宏定義那改一下就好了。

Adapting to the True Tone Display 真彩色顯示
真彩色的顯示會(huì)根據(jù)光感應(yīng)器來進(jìn)行自動(dòng)的調(diào)節(jié)來達(dá)到特定環(huán)境下的顯示與性能平衡效果。 如果需要這個(gè)功能的話需要再info.plist里配置
UIWhitePointAdaptivityStyle 共有五種選擇: 1.UIWhitePointAdaptivityStyleStandard 標(biāo)準(zhǔn) 2.UIWhitePointAdaptivityStyleReading 閱讀 3.UIWhitePointAdaptivityStylePhoto 圖片 4.UIWhitePointAdaptivityStyleVideo 視頻 5.UIWhitePointAdaptivityStyleGame 游戲
然后他說的很清楚,如果你是圖片處理類的app,那就直接配stylePhoto吧,如果你是閱讀類的那就直接配styleReading吧。 這五個(gè)形式的顯示效果從上往下遞減,我理解是說在閱讀時(shí)給你最好的效果,但如果在游戲時(shí)也給那么好的效果會(huì)影響性能,就給你一個(gè)相對(duì)次一點(diǎn)的顯示效果讓性能更流暢。
App Search Enhancements 應(yīng)用搜索增強(qiáng)
iOS10的搜索功能做了一定增強(qiáng):應(yīng)用程序內(nèi)搜索,搜索傳遞,考慮私人差異,結(jié)果可視化。 使用CSSearchQuery類,調(diào)用Core Spotlight的api,可以讓你不必自己維護(hù)自己的搜索索引,關(guān)于對(duì)搜索關(guān)鍵字的處理,還有考慮到不同類別差異導(dǎo)致搜索結(jié)果的排序都是蘋果幫你處理。
并且搜索結(jié)果可以繼續(xù)往下傳遞,假設(shè)你用Core Spotlight搜索火車站,提示的是地圖類app搜索火車站的結(jié)果,你點(diǎn)進(jìn)去后,這個(gè)地圖類app會(huì)接收到“火車站”這個(gè)字段在應(yīng)用內(nèi)也完成搜索。支持此功能也是需要配置plist文件:key-value CoreSpotlightContinuation-YES,然后設(shè)置CSQueryContinuationActionType(#import
Security and Privacy Enhancements 安全和保密性增強(qiáng)
安全方面在iOS10中引入了更多修改和補(bǔ)充,具體有以下幾點(diǎn):
1.在info.plist文件新增了一個(gè)key,NSAllowsArbitraryLoadsInWebContent,允許任意web頁(yè)面加載,同時(shí)蘋果會(huì)用ATS保護(hù)你的app。
2.使用改進(jìn)后的SecKey API 而不是過時(shí)的 CDSA API。
3.安全傳輸API中不再支持SSLv3, 建議你們盡快停用SHA1和3DES加密算法
4.剪貼板的擴(kuò)展,因?yàn)閣wdc2016演示了可以跨設(shè)備復(fù)制粘貼啊,那肯定要做一些限制可見(#import

NSBluetoothPeripheralUsageDescription
NSCalendarsUsageDescription
NSCameraUsageDescription
NSContactsUsageDescription
NSHealthShareUsageDescription
NSHealthUpdateUsageDescription
NSHomeKitUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSMicrophoneUsageDescription
NSMotionUsageDescription
NSPhotoLibraryUsageDescription
NSRemindersUsageDescription
NSSiriUsageDescription
NSSpeechRecognitionUsageDescription
NSVideoSubscriberAccountUsageDescription
NSVoIPUsageDescription

NSContactsUsageDescription,剛啟動(dòng)時(shí)不會(huì)崩潰,但是在喚起操作發(fā)生時(shí)會(huì)直接崩潰。 在info.plist設(shè)置之后就可以正常使用了。

字體變化

字體在iOS9較iOS8變粗變寬了, iOS10較iOS9變粗變寬了.

20161008190538555.png

iOS10 適配教程

ATS的問題

iOS 9中默認(rèn)非HTTS的網(wǎng)絡(luò)是被禁止的,當(dāng)然我們也可以把NSAllowsArbitraryLoads設(shè)置為YES禁用ATS。不過ios 10從2017年1月1日起蘋果不允許我們通過這個(gè)方法跳過ATS,也就是說強(qiáng)制我們用HTTPS,如果不這樣的話提交App可能會(huì)被拒絕。但是我們可以通過NSExceptionDomains來針對(duì)特定的域名開放HTTP可以容易通過審核。
NSExceptionDomains方式 設(shè)置域。可以簡(jiǎn)單理解成,把不支持https協(xié)議的接口設(shè)置成http的接口。
具體方法: 1、在項(xiàng)目的info.plist中添加一個(gè)Key:App Transport Security Settings,類型為字典類型。 2、然后給它添加一個(gè)Exception Domains,類型為字典類型; 3、把需要的支持的域添加給Exception Domains。其中域作為Key,類型為字典類型。 4、每個(gè)域下面需要設(shè)置3個(gè)屬性:NSIncludesSubdomains、NSExceptionRequiresForwardSecrecy、NSExceptionAllowsInsecureHTTPLoads。

20161008190810542.png

這里需要將你的接口請(qǐng)求域名, 網(wǎng)絡(luò)圖片域名, 還有項(xiàng)目中涉及到的http域名都進(jìn)行如此處理. 在iOS9以后的系統(tǒng)中如果使用到網(wǎng)絡(luò)圖片,也要注意網(wǎng)絡(luò)圖片是否是HTTP的哦,如果是,也要把圖片的域設(shè)置!
以iOS10 SDK編譯的工程會(huì)默認(rèn)以SSL安全協(xié)議進(jìn)行網(wǎng)絡(luò)傳輸,即HTTPS,如果依然使用HTTP協(xié)議請(qǐng)求網(wǎng)絡(luò)會(huì)報(bào)系統(tǒng)異常并中斷請(qǐng)求。目前可用如下兩種方式保持用HTTP進(jìn)行網(wǎng)絡(luò)連接, 以下為部分是umeng給出的相應(yīng)白名單,由技術(shù)人員測(cè)試各個(gè)平臺(tái)所收集而來,如果有所遺漏,請(qǐng)自行加入:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>log.umsns.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
        <key>sns.whalecloud.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>

        <!-- 集成新浪微博對(duì)應(yīng)的HTTP白名單-->
        <key>sina.cn</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>sina.cn</key>
            <dict>
                <!-- 適配iOS10 -->
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
      <key>weibo.cn</key>
            <dict>
                <!-- 適配iOS10 -->
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
      <key>weibo.com</key>
      <dict>
                <!-- 適配iOS10 -->
        <key>NSExceptionMinimumTLSVersion</key>
        <string>TLSv1.0</string>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
        <key>sinaimg.cn</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>sinajs.cn</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>sina.com.cn</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <!-- 新浪微博-->

        <!-- 集成微信、QQ、Qzone、騰訊微博授權(quán)對(duì)應(yīng)的HTTP白名單-->
        <key>qq.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <!-- 騰訊授權(quán)-->

        <!-- 集成人人授權(quán)對(duì)應(yīng)的HTTP白名單-->
        <key>renren.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <!-- 人人授權(quán)-->

        <!-- 集成Facebook授權(quán)對(duì)應(yīng)的HTTP白名單-->
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <!-- Facebook授權(quán)-->

        <!-- 集成Twitter授權(quán)對(duì)應(yīng)的HTTP白名單-->
        <key>twitter.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <!-- Twitter授權(quán)-->
    </dict>
</dict>

隱私權(quán)限設(shè)置

iOS 10 開始對(duì)隱私權(quán)限更加嚴(yán)格,如果你不設(shè)置就會(huì)直接崩潰,現(xiàn)在很多遇到崩潰問題了,一般解決辦法都是在info.plist文件添加對(duì)應(yīng)的Key-Value就可以了。

20161008191251564.png
<!-- 相冊(cè) --> 
<key>NSPhotoLibraryUsageDescription</key> 
<string>App需要您的同意,才能訪問相冊(cè)</string> 
<!-- 相機(jī) --> 
<key>NSCameraUsageDescription</key> 
<string>App需要您的同意,才能訪問相機(jī)</string> 
<!-- 麥克風(fēng) --> 
<key>NSMicrophoneUsageDescription</key> 
<string>App需要您的同意,才能訪問麥克風(fēng)</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> 
<!-- 提醒事項(xiàng) --> 
<key>NSRemindersUsageDescription</key> 
<string>App需要您的同意,才能訪問提醒事項(xiàng)</string> 
<!-- 運(yùn)動(dòng)與健身 --> 
<key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問運(yùn)動(dòng)與健身</string> 
<!-- 健康更新 --> 
<key>NSHealthUpdateUsageDescription</key> 
<string>App需要您的同意,才能訪問健康更新 </string> 
<!-- 健康分享 --> 
<key>NSHealthShareUsageDescription</key> 
<string>App需要您的同意,才能訪問健康分享</string> 
<!-- 藍(lán)牙 --> 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>App需要您的同意,才能訪問藍(lán)牙</string> 
<!-- 媒體資料庫(kù) --> 
<key>NSAppleMusicUsageDescription</key> 
<string>App需要您的同意,才能訪問媒體資料庫(kù)</string>

出現(xiàn)許多自己沒有添加的log日志

20161008191523831.jpeg

若控制臺(tái)輸出“[] tcp_connection_xxx“等內(nèi)容,可以在運(yùn)行按鈕旁的選擇target選項(xiàng)內(nèi)的 Edit Scheme - Run - Arguments - Enviroment variables中增加OS_ACTIVITY_MODE=disable,可將相關(guān)日志關(guān)閉。

解決:
打開項(xiàng)目, Edit Scheme 進(jìn)入


20161008191619018.png

添加參數(shù):
Name :OS_ACTIVITY_MODE
Value : disable

Notification

自從Notification被引入之后,蘋果就不斷的更新優(yōu)化,但這些更新優(yōu)化只是小打小鬧,直至現(xiàn)在iOS 10開始真正的進(jìn)行大改重構(gòu),這讓開發(fā)者也體會(huì)到UserNotifications的易用,功能也變得非常強(qiáng)大。

iOS 9 以前的通知

1.在調(diào)用方法時(shí),有些方法讓人很難區(qū)分,容易寫錯(cuò)方法,這讓開發(fā)者有時(shí)候很苦惱。
2.應(yīng)用在運(yùn)行時(shí)和非運(yùn)行時(shí)捕獲通知的路徑還不一致。
3.應(yīng)用在前臺(tái)時(shí),是無法直接顯示遠(yuǎn)程通知,還需要進(jìn)一步處理。
4.已經(jīng)發(fā)出的通知是不能更新的,內(nèi)容發(fā)出時(shí)是不能改變的,并且只有簡(jiǎn)單文本展示方式,擴(kuò)展性根本不是很好。

iOS 10 開始的通知

1.所有相關(guān)通知被統(tǒng)一到了UserNotifications.framework框架中。
2.增加了撤銷、更新、中途還可以修改通知的內(nèi)容。
3.通知不在是簡(jiǎn)單的文本了,可以加入視頻、圖片,自定義通知的展示等等。
4.iOS 10相對(duì)之前的通知來說更加好用易于管理,并且進(jìn)行了大規(guī)模優(yōu)化,對(duì)于開發(fā)者來說是一件好事。
5.iOS 10開始對(duì)于權(quán)限問題進(jìn)行了優(yōu)化,申請(qǐng)權(quán)限就比較簡(jiǎn)單了(本地與遠(yuǎn)程通知集成在一個(gè)方法中)。

如果使用了推送,修改如圖:

20161008192424602.png

注:推送的時(shí)候,開啟Remote notifications可能會(huì)下面這樣
You’ve implemented -[< UIApplicationDelegate > application:didReceiveRemoteNotification:fetchCompletionHandler:],
but you still need to add “remote-notification” to the list of your supported UIBackgroundModes in your Info.plist.
解決方案:需要在Xcode 中修改應(yīng)用的 Capabilities 開啟Remote notifications,請(qǐng)參考下圖:
20161008192616446.png

判斷系統(tǒng)版本正確方式

在你的項(xiàng)目中,當(dāng)需要判斷系統(tǒng)版本的話,不要使用下面的方法:

#define isiOS10 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=10)

它會(huì)永遠(yuǎn)返回NO,substringToIndex:1在iOS 10 會(huì)被檢測(cè)成 iOS 1了, 應(yīng)該使用下面的這些方法: Objective-C 中這樣寫:

#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

或者使用:

if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 1, .patchVersion = 0}]) { NSLog(@"Hello from > iOS 9.1");}
if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,3,0}]) { NSLog(@"Hello from > iOS 9.3");
}

或者使用:

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_0) { // do stuff for iOS 9 and newer} else { // do stuff for older versions than iOS 9}

有時(shí)候會(huì)缺少一些常量,NSFoundationVersionNumber是在NSObjCRuntime.h中定義的,作為Xcode7.3.1的一部分,我們?cè)O(shè)定常熟范圍從iPhone OS 2到#define NSFoundationVersionNumber_iOS_8_4 1144.17,在iOS 10(Xcode 8)中,蘋果補(bǔ)充了缺少的數(shù)字,設(shè)置有未來的版本.

#define NSFoundationVersionNumber_iOS_9_0 1240.1
#define NSFoundationVersionNumber_iOS_9_1 1241.14
#define NSFoundationVersionNumber_iOS_9_2 1242.12
#define NSFoundationVersionNumber_iOS_9_3 1242.12
#define NSFoundationVersionNumber_iOS_9_4 1280.25
#define NSFoundationVersionNumber_iOS_9_x_Max 1299

UIStatusBar的問題(待確認(rèn))
在iOS10中,如果還使用以前設(shè)置UIStatusBar類型或者控制隱藏還是顯示的方法,會(huì)報(bào)警告,方法過期,如下圖:

這里寫圖片描述

上面方法到 iOS 10 不能使用了,要想修改UIStatusBar的樣式或者狀態(tài)使用下圖中所示的屬性或方法:

@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
- (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

awakeFromNib的警告問題

在Xcode 8之前我們使用Xib初始化- (void)awakeFromNib {}都是這么寫也沒什么問題,但是在Xcode 8會(huì)有如下警告:
在Xcode 8之前我們使用Xib初始化- (void)awakeFromNib {}都是這么寫也沒什么問題,但是在Xcode 8會(huì)有如下警告:

20161008193801112.png

官方解釋:

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. 
Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. 
You may call the super implementation at any point during your own awakeFromNib method.

你必須調(diào)用父類實(shí)現(xiàn)awakeFromNib來給父類來執(zhí)行它們需要的任何額外的初始化的機(jī)會(huì)。
雖然這種方法的默認(rèn)實(shí)現(xiàn)不做任何事情,許多UIKit類提供非空的實(shí)現(xiàn)。
你可以調(diào)用自己的awakeFromNib方法中的任何時(shí)候超級(jí)實(shí)現(xiàn)。

XCode8新特性
證書管理
直接使用Xcode8打開工程后,你會(huì)發(fā)現(xiàn)你的provisonfile配置出了問題,這是由于在Xcode8中對(duì)工程配置有了一些小的改動(dòng)。 在Xcode8工程配置的general選項(xiàng)卡中,使用更詳細(xì)signing選項(xiàng)替換了原有的team選項(xiàng)。 選中:project -> target -> general
Xcode8之前provisionfile選項(xiàng) :

20161008201008314.png

Xcode8之后, 將build setting中的code signing中的配置項(xiàng)放在project -> target -> general中了.
用Xcode8打開工程后,比較明顯的就是下圖了,這個(gè)是蘋果的新特性,可以幫助我們自動(dòng)管理證書。建議大家勾選這個(gè)Automatically manage signing.

20161008201451734.png

This iPhone 4 is running iOS 7.1.12(11D257),which may not be supported by this version of Xcode.
對(duì)于Xcode8的發(fā)布,蘋果也是來了個(gè)大的跳躍,默認(rèn)最低支持的iOS版本為8.0,當(dāng)然也并不是說8.0以下就直接放棄了,雖然表現(xiàn)出來的是這樣,畢竟使用8.0以下系統(tǒng)的還是大有人在的,老項(xiàng)目要兼容iOS8以下也是可以另辟蹊徑的。
首先我們要找到Xcode是通過什么來兼容iOS版本的,請(qǐng)打開以下路徑:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,在文件夾中我們能夠看到Xcode支持的iOS版本,從8.0開始,唯獨(dú)沒有8.0以下的,所以我們第一步要做的就是把需要支持的iOS版本的配置包放進(jìn)來,博主這里支持到7.0,包括7.1,當(dāng)然也可以支持6.0等等….. iOS6/iOS7的SDK下載地址為:SDK下載地址
到這里并沒有結(jié)束,接下來需要配置Xcode,打開以下路徑:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ,在這里我們要改點(diǎn)東西,但是在這個(gè)文件夾里的東西是鎖定的,首先右鍵‘空白部分’,點(diǎn)擊顯示簡(jiǎn)介,滑動(dòng)到最下面,點(diǎn)擊小鎖打開權(quán)限,需要輸入管理員密碼,接著把所有的權(quán)限改為讀寫,第一步完成,接下來,右鍵SDKSettings.plist文件夾,和上面同樣的操作,打開讀寫權(quán)限,然后雙擊打開SDKSettings.plist文件,如圖:

20161008195733694.jpeg

在這個(gè)下面添加7.0和7.1,按照從小到大的順序排好。接著重啟電腦即可,結(jié)束的時(shí)候別忘了把剛才改的權(quán)限都改回去以防不小心動(dòng)了不該動(dòng)的。
看Xcode里面:

20161008195809657.jpeg

已經(jīng)可以看到7.0和7.1了,如果需要支持更低的版本,跟上面同樣的方法,只需要添加對(duì)應(yīng)的配置文件即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容