110.iOS10新特性適配教程XCode8新特性解析
iOS10 新特性
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è)頭文件(#import
Proactive Suggestions 系統(tǒng)預(yù)先建議
背景就是iOS9的時(shí)候系統(tǒng)給予的主動(dòng)建議會(huì)通過(guò):Spolight搜索,Safari搜索,Handoff,或者siri建議。 在iOS10之后新增了,鍵盤(pán)QuickType建議,地圖,車(chē)載娛樂(lè),應(yīng)用切換,siri交互,鎖屏播放。 比如你正在一個(gè)應(yīng)用里看一個(gè)酒店,可以使用mapitem屬性保存正在查看的這個(gè)酒店的位置,然后你切換旅行或地圖App時(shí)這個(gè)位置可以自動(dòng)提供使用。 如果你需要這樣利用系統(tǒng)來(lái)共享一個(gè)位置,那你需要指定這個(gè)位置的經(jīng)緯度,地名,電話等屬性 來(lái)便于siri的直接調(diào)起。
User Notifications 用戶通知
總體的意思就是支持了很多用戶定義的通知,并且可以捕捉到各個(gè)通知狀態(tài)的回調(diào)。以往通知的概念是:大家想接收的都提前做好準(zhǔn)備,然后一下全量分發(fā),沒(méi)收到也不管了,也不關(guān)心發(fā)送者?,F(xiàn)在用戶通知做成了和網(wǎng)絡(luò)請(qǐng)求有點(diǎn)像 一個(gè)先發(fā)request再得到response的流程,甚至封裝了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
在iOS 10 中,UITextField新增了textContentType字段,是UITextContentType類(lèi)型,它是一個(gè)枚舉,作用是可以指定輸入框的類(lèi)型,以便系統(tǒng)可以分析出用戶的語(yǔ)義.是電話類(lèi)型就建議一些電話,是地址類(lèi)型就建議一些地址.可以在#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上說(shuō)的各種消息內(nèi)的新操作在頭文件中都能找到Api。
Speech Recognition 語(yǔ)音識(shí)別轉(zhuǎn)文字
這個(gè)類(lèi)里面的Api和方法調(diào)用都非常清晰,感覺(jué)使用起來(lái)會(huì)非常方便。真的為科大訊飛捏把汗了,科大訊飛的app(錄音寶)我看過(guò),都還沒(méi)有說(shuō)一段語(yǔ)音能直接轉(zhuǎn)文字的功能,他們是直接把聲音文件上傳,然后24小時(shí)候再發(fā)給你轉(zhuǎn)換后的結(jié)果…而且一上來(lái)就要收費(fèi)。蘋(píng)果的這個(gè)功能已經(jīng)做到了系統(tǒng)原生支持,真的厲害。
Wide Color 寬域顏色
文檔的原話說(shuō):大多數(shù)的 core字打頭的圖形框架 還有AVFoundation 都大大提高了對(duì)擴(kuò)展像素和寬色域色彩空間的支持。通過(guò)圖形堆棧擴(kuò)展這種方式比以往支持廣色域的顯示設(shè)備更加容易?,F(xiàn)在對(duì)UIKit擴(kuò)展可以在sRGB的色彩空間下工作,性能更好,也可以在更廣泛的色域來(lái)搭配sRGB顏色。 然后說(shuō)了幾個(gè)場(chǎng)景說(shuō)建議你用sRGB吧,比如依賴于UIkit的clamp component values的應(yīng)用程序,或是使用較低級(jí)別api執(zhí)行自己圖像處理的 都建議用sRGB吧。
然后看了下UIColor類(lèi)里 到底什么是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è)類(lèi)方法一個(gè)實(shí)例方法, 我理解下,就是說(shuō)建議你們以前改用colorwithRGB的地方 現(xiàn)在都換成這個(gè)方法叭??赡艽蠖鄶?shù)公司都抽成了 RGB(a,g,b,a)這種宏吧,那就在宏定義那改一下就好了?!?/p>
Adapting to the True Tone Display 真彩色顯示
真彩色的顯示會(huì)根據(jù)光感應(yīng)器來(lái)進(jìn)行自動(dòng)的調(diào)節(jié)來(lái)達(dá)到特定環(huán)境下的顯示與性能平衡效果。 如果需要這個(gè)功能的話需要再info.plist里配置
UIWhitePointAdaptivityStyle
共有五種選擇:
1.UIWhitePointAdaptivityStyleStandard 標(biāo)準(zhǔn)
2.UIWhitePointAdaptivityStyleReading 閱讀
3.UIWhitePointAdaptivityStylePhoto 圖片
4.UIWhitePointAdaptivityStyleVideo 視頻
5.UIWhitePointAdaptivityStyleGame 游戲
然后他說(shuō)的很清楚,如果你是圖片處理類(lèi)的app,那就直接配stylePhoto吧,如果你是閱讀類(lèi)的那就直接配styleReading吧。 這五個(gè)形式的顯示效果從上往下遞減,我理解是說(shuō)在閱讀時(shí)給你最好的效果,但如果在游戲時(shí)也給那么好的效果會(huì)影響性能,就給你一個(gè)相對(duì)次一點(diǎn)的顯示效果讓性能更流暢。
App Search Enhancements 應(yīng)用搜索增強(qiáng)
iOS10的搜索功能做了一定增強(qiáng):應(yīng)用程序內(nèi)搜索,搜索傳遞,考慮私人差異,結(jié)果可視化。 使用CSSearchQuery類(lèi),調(diào)用Core Spotlight的api,可以讓你不必自己維護(hù)自己的搜索索引,關(guān)于對(duì)搜索關(guān)鍵字的處理,還有考慮到不同類(lèi)別差異導(dǎo)致搜索結(jié)果的排序都是蘋(píng)果幫你處理。
并且搜索結(jié)果可以繼續(xù)往下傳遞,假設(shè)你用Core Spotlight搜索火車(chē)站,提示的是地圖類(lèi)app搜索火車(chē)站的結(jié)果,你點(diǎn)進(jìn)去后,這個(gè)地圖類(lèi)app會(huì)接收到“火車(chē)站”這個(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í)蘋(píng)果會(huì)用ATS保護(hù)你的app。
2.使用改進(jìn)后的SecKey API 而不是過(guò)時(shí)的 CDSA API。
3.安全傳輸API中不再支持SSLv3, 建議你們盡快停用SHA1和3DES加密算法。
4.剪貼板的擴(kuò)展,因?yàn)閣wdc2016演示了可以跨設(shè)備復(fù)制粘貼啊,那肯定要做一些限制可見(jiàn)(#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變粗變寬了.
iOS10 適配教程
ATS的問(wèn)題
iOS 9中默認(rèn)非HTTS的網(wǎng)絡(luò)是被禁止的,當(dāng)然我們也可以把NSAllowsArbitraryLoads設(shè)置為YES禁用ATS。不過(guò)iOS 10從2017年1月1日起蘋(píng)果不允許我們通過(guò)這個(gè)方法跳過(guò)ATS,也就是說(shuō)強(qiáng)制我們用HTTPS,如果不這樣的話提交App可能會(huì)被拒絕。但是我們可以通過(guò)NSExceptionDomains來(lái)針對(duì)特定的域名開(kāi)放HTTP可以容易通過(guò)審核。
NSExceptionDomains方式 設(shè)置域。可以簡(jiǎn)單理解成,把不支持https協(xié)議的接口設(shè)置成http的接口。
具體方法:
1、在項(xiàng)目的info.plist中添加一個(gè)Key:App Transport Security Settings,類(lèi)型為字典類(lèi)型。
2、然后給它添加一個(gè)Exception Domains,類(lèi)型為字典類(lèi)型;
3、把需要的支持的域添加給Exception Domains。其中域作為Key,類(lèi)型為字典類(lèi)型。
4、每個(gè)域下面需要設(shè)置3個(gè)屬性:NSIncludesSubdomains、NSExceptionRequiresForwardSecrecy、NSExceptionAllowsInsecureHTTPLoads。
細(xì)節(jié)提示:在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)所收集而來(lá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 開(kāi)始對(duì)隱私權(quán)限更加嚴(yán)格,如果你不設(shè)置就會(huì)直接崩潰,現(xiàn)在很多遇到崩潰問(wèn)題了,一般解決辦法都是在info.plist文件添加對(duì)應(yīng)的Key-Value就可以了。
<!-- 相冊(cè) --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)相冊(cè)</string> <!-- 相機(jī) --> <key>NSCameraUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)相機(jī)</string> <!-- 麥克風(fēng) --> <key>NSMicrophoneUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)麥克風(fēng)</string> <!-- 位置 --> <key>NSLocationUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)位置</string> <!-- 在使用期間訪問(wèn)位置 --> <key>NSLocationWhenInUseUsageDescription</key> <string>App需要您的同意,才能在使用期間訪問(wèn)位置</string> <!-- 始終訪問(wèn)位置 --> <key>NSLocationAlwaysUsageDescription</key> <string>App需要您的同意,才能始終訪問(wèn)位置</string> <!-- 日歷 --> <key>NSCalendarsUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)日歷</string> <!-- 提醒事項(xiàng) --> <key>NSRemindersUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)提醒事項(xiàng)</string> <!-- 運(yùn)動(dòng)與健身 --> <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)運(yùn)動(dòng)與健身</string> <!-- 健康更新 --> <key>NSHealthUpdateUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)健康更新 </string> <!-- 健康分享 --> <key>NSHealthShareUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)健康分享</string> <!-- 藍(lán)牙 --> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)藍(lán)牙</string> <!-- 媒體資料庫(kù) --> <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能訪問(wèn)媒體資料庫(kù)</string>
出現(xiàn)許多自己沒(méi)有添加的log日志
若控制臺(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)閉。
解決:
打開(kāi)項(xiàng)目, Edit Scheme 進(jìn)入
添加參數(shù):
Name :OS_ACTIVITY_MODE
Value : disable
Notification
自從Notification被引入之后,蘋(píng)果就不斷的更新優(yōu)化,但這些更新優(yōu)化只是小打小鬧,直至現(xiàn)在iOS 10開(kāi)始真正的進(jìn)行大改重構(gòu),這讓開(kāi)發(fā)者也體會(huì)到UserNotifications的易用,功能也變得非常強(qiáng)大。
iOS 9 以前的通知
1.在調(diào)用方法時(shí),有些方法讓人很難區(qū)分,容易寫(xiě)錯(cuò)方法,這讓開(kāi)發(fā)者有時(shí)候很苦惱。
2.應(yīng)用在運(yùn)行時(shí)和非運(yùn)行時(shí)捕獲通知的路徑還不一致。
3.應(yīng)用在前臺(tái)時(shí),是無(wú)法直接顯示遠(yuǎn)程通知,還需要進(jìn)一步處理。
4.已經(jīng)發(fā)出的通知是不能更新的,內(nèi)容發(fā)出時(shí)是不能改變的,并且只有簡(jiǎn)單文本展示方式,擴(kuò)展性根本不是很好。
iOS 10 開(kāi)始的通知
1.所有相關(guān)通知被統(tǒng)一到了UserNotifications.framework框架中。
2.增加了撤銷(xiāo)、更新、中途還可以修改通知的內(nèi)容。
3.通知不在是簡(jiǎn)單的文本了,可以加入視頻、圖片,自定義通知的展示等等。
4.iOS 10相對(duì)之前的通知來(lái)說(shuō)更加好用易于管理,并且進(jìn)行了大規(guī)模優(yōu)化,對(duì)于開(kāi)發(fā)者來(lái)說(shuō)是一件好事。
5.iOS 10開(kāi)始對(duì)于權(quán)限問(wèn)題進(jìn)行了優(yōu)化,申請(qǐng)權(quán)限就比較簡(jiǎn)單了(本地與遠(yuǎn)程通知集成在一個(gè)方法中)。
如果使用了推送,修改如圖:
注:推送的時(shí)候,開(kāi)啟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 開(kāi)啟Remote notifications,請(qǐng)參考下圖:
判斷系統(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 中這樣寫(xiě):
#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)中,蘋(píng)果補(bǔ)充了缺少的數(shù)字,設(shè)置有未來(lái)的版本.
#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的問(wèn)題(待確認(rèn))
在iOS10中,如果還使用以前設(shè)置UIStatusBar類(lèi)型或者控制隱藏還是顯示的方法,會(huì)報(bào)警告,方法過(guò)期,如下圖:
上面方法到 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的警告問(wèn)題
在Xcode 8之前我們使用Xib初始化- (void)awakeFromNib {}都是這么寫(xiě)也沒(méi)什么問(wèn)題,但是在Xcode 8會(huì)有如下警告:
在Xcode 8之前我們使用Xib初始化- (void)awakeFromNib {}都是這么寫(xiě)也沒(méi)什么問(wèn)題,但是在Xcode 8會(huì)有如下警告:
官方解釋?zhuān)?/p>
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)用父類(lèi)實(shí)現(xiàn)awakeFromNib來(lái)給父類(lèi)來(lái)執(zhí)行它們需要的任何額外的初始化的機(jī)會(huì)。
雖然這種方法的默認(rèn)實(shí)現(xiàn)不做任何事情,許多UIKit類(lèi)提供非空的實(shí)現(xiàn)。
你可以調(diào)用自己的awakeFromNib方法中的任何時(shí)候超級(jí)實(shí)現(xiàn)。
XCode8新特性
證書(shū)管理
直接使用Xcode8打開(kāi)工程后,你會(huì)發(fā)現(xiàn)你的provisonfile配置出了問(wèn)題,這是由于在Xcode8中對(duì)工程配置有了一些小的改動(dòng)。
在Xcode8工程配置的general選項(xiàng)卡中,使用更詳細(xì)signing選項(xiàng)替換了原有的team選項(xiàng)。
選中:project -> target -> general
Xcode8之前provisionfile選項(xiàng) :
Xcode8之后, 將build setting中的code signing中的配置項(xiàng)放在project -> target -> general中了.
用Xcode8打開(kāi)工程后,比較明顯的就是下圖了,這個(gè)是蘋(píng)果的新特性,可以幫助我們自動(dòng)管理證書(shū)。建議大家勾選這個(gè)Automatically manage signing.
讓XCode8支持iOS7及之前版本
This iPhone 4 is running iOS 7.1.12(11D257),which may not be supported by this version of Xcode.
對(duì)于Xcode8的發(fā)布,蘋(píng)果也是來(lái)了個(gè)大的跳躍,默認(rèn)最低支持的iOS版本為8.0,當(dāng)然也并不是說(shuō)8.0以下就直接放棄了,雖然表現(xiàn)出來(lái)的是這樣,畢竟使用8.0以下系統(tǒng)的還是大有人在的,老項(xiàng)目要兼容iOS8以下也是可以另辟蹊徑的。
首先我們要找到Xcode是通過(guò)什么來(lái)兼容iOS版本的,請(qǐng)打開(kāi)以下路徑:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,在文件夾中我們能夠看到Xcode支持的iOS版本,從8.0開(kāi)始,唯獨(dú)沒(méi)有8.0以下的,所以我們第一步要做的就是把需要支持的iOS版本的配置包放進(jìn)來(lái),博主這里支持到7.0,包括7.1,還有6.0…..
跳轉(zhuǎn) www.cnblogs.com/starainDou/p/5325643.html 下載
到這里并沒(méi)有結(jié)束,接下來(lái)需要配置Xcode,打開(kāi)以下路徑:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
,在這里我們要改點(diǎn)東西,但是在這個(gè)文件夾里的東西是鎖定的,首先右鍵‘空白部分',點(diǎn)擊顯示簡(jiǎn)介,滑動(dòng)到最下面,點(diǎn)擊小鎖打開(kāi)權(quán)限,需要輸入管理員密碼,接著把所有的權(quán)限改為讀寫(xiě),第一步完成,接下來(lái),右鍵SDKSettings.plist文件夾,和上面同樣的操作,打開(kāi)讀寫(xiě)權(quán)限,然后雙擊打開(kāi)SDKSettings.plist文件,如圖:
在這個(gè)下面添加7.0和7.1,按照從小到大的順序排好。接著重啟電腦即可,結(jié)束的時(shí)候別忘了把剛才改的權(quán)限都改回去以防不小心動(dòng)了不該動(dòng)的。
看Xcode里面:
已經(jīng)可以看到7.0和7.1了,如果需要支持更低的版本,跟上面同樣的方法,只需要添加對(duì)應(yīng)的配置文件即可。
相關(guān)文章
iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法
這篇文章主要介紹了iphone的safari瀏覽器中實(shí)現(xiàn)全屏瀏覽的方法,同時(shí)介紹了Add to Home Screen功能的實(shí)現(xiàn)方法,需要的朋友可以參考下2014-06-06iOS App設(shè)計(jì)模式開(kāi)發(fā)中對(duì)迭代器模式的使用示例
這篇文章主要介紹了iOS App設(shè)計(jì)模式開(kāi)發(fā)中對(duì)迭代器模式的使用示例,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-03-03IOS開(kāi)發(fā)壓縮后圖片模糊問(wèn)題解決
這篇文章主要為大家介紹了IOS開(kāi)發(fā)壓縮后圖片模糊問(wèn)題解決實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07設(shè)計(jì)模式中的Memento備忘錄模式的在iOS App開(kāi)發(fā)中的運(yùn)用
這篇文章主要介紹了設(shè)計(jì)模式中的Memento備忘錄模式的在iOS App開(kāi)發(fā)中的運(yùn)用,Memento著重于捕獲和具體化當(dāng)前對(duì)象的內(nèi)部狀態(tài),需要的朋友可以參考下2016-03-03iOS App開(kāi)發(fā)中UITextField組件的常用屬性小結(jié)
這篇文章主要介紹了iOS App開(kāi)發(fā)中UITextField組件的常用屬性小結(jié),文中還介紹了UITextField隱藏鍵盤(pán)及為內(nèi)容增加校驗(yàn)的兩個(gè)使用技巧,需要的朋友可以參考下2016-04-04