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