你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 110.iOS10新特性適配教程XCode8新特性解析

110.iOS10新特性適配教程XCode8新特性解析

編輯:IOS開發綜合

iOS10 新特性

SiriKit

SiriKit的功能非常強大,支持音頻、視頻、消息發送接收、搜索照片、預訂行程、管理鍛煉等等。在用到此服務時,siri會發送Intent對象,裡面包括用戶的請求和各種數據,可以對這個intent處理選擇適當的響應。 這個功能主要是看這兩個頭文件(#import

Proactive Suggestions 系統預先建議

背景就是iOS9的時候系統給予的主動建議會通過:Spolight搜索,Safari搜索,Handoff,或者siri建議。 在iOS10之後新增了,鍵盤QuickType建議,地圖,車載娛樂,應用切換,siri交互,鎖屏播放。 比如你正在一個應用裡看一個酒店,可以使用mapitem屬性保存正在查看的這個酒店的位置,然後你切換旅行或地圖App時這個位置可以自動提供使用。 如果你需要這樣利用系統來共享一個位置,那你需要指定這個位置的經緯度,地名,電話等屬性 來便於siri的直接調起。

User Notifications 用戶通知

總體的意思就是支持了很多用戶定義的通知,並且可以捕捉到各個通知狀態的回調。以往通知的概念是:大家想接收的都提前做好准備,然後一下全量分發,沒收到也不管了,也不關心發送者。現在用戶通知做成了和網絡請求有點像 一個先發request再得到response的流程,甚至封裝了error,可以在各個狀態的方法中做一些額外操作,並且也能取到一些字段,如發送者等。這個功能的頭文件是:#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類型,它是一個枚舉,作用是可以指定輸入框的類型,以便系統可以分析出用戶的語義.是電話類型就建議一些電話,是地址類型就建議一些地址.可以在#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 與系統短信 app交互

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

Speech Recognition 語音識別轉文字

這個類裡面的Api和方法調用都非常清晰,感覺使用起來會非常方便。真的為科大訊飛捏把汗了,科大訊飛的app(錄音寶)我看過,都還沒有說一段語音能直接轉文字的功能,他們是直接把聲音文件上傳,然後24小時候再發給你轉換後的結果…而且一上來就要收費。蘋果的這個功能已經做到了系統原生支持,真的厲害。

Wide Color 寬域顏色

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

然後看了下UIColor類裡 到底什麼是sRGB? 發現多了兩個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);

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

Adapting to the True Tone Display 真彩色顯示

真彩色的顯示會根據光感應器來進行自動的調節來達到特定環境下的顯示與性能平衡效果。 如果需要這個功能的話需要再info.plist裡配置

UIWhitePointAdaptivityStyle

共有五種選擇:

1.UIWhitePointAdaptivityStyleStandard 標准

2.UIWhitePointAdaptivityStyleReading 閱讀

3.UIWhitePointAdaptivityStylePhoto 圖片

4.UIWhitePointAdaptivityStyleVideo 視頻

5.UIWhitePointAdaptivityStyleGame 游戲

然後他說的很清楚,如果你是圖片處理類的app,那就直接配stylePhoto吧,如果你是閱讀類的那就直接配styleReading吧。 這五個形式的顯示效果從上往下遞減,我理解是說在閱讀時給你最好的效果,但如果在游戲時也給那麼好的效果會影響性能,就給你一個相對次一點的顯示效果讓性能更流暢。

App Search Enhancements 應用搜索增強

iOS10的搜索功能做了一定增強:應用程序內搜索,搜索傳遞,考慮私人差異,結果可視化。 使用CSSearchQuery類,調用Core Spotlight的api,可以讓你不必自己維護自己的搜索索引,關於對搜索關鍵字的處理,還有考慮到不同類別差異導致搜索結果的排序都是蘋果幫你處理。

並且搜索結果可以繼續往下傳遞,假設你用Core Spotlight搜索火車站,提示的是地圖類app搜索火車站的結果,你點進去後,這個地圖類app會接收到“火車站”這個字段在應用內也完成搜索。支持此功能也是需要配置plist文件:key-value CoreSpotlightContinuation-YES,然後設置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演示了可以跨設備復制粘貼啊,那肯定要做一些限制可見(#import

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

NSContactsUsageDescription,剛啟動時不會崩潰,但是在喚起操作發生時會直接崩潰。 在info.plist設置之後就可以正常使用了。

字體變化

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

這裡寫圖片描述

iOS10 適配教程

ATS的問題

iOS 9中默認非HTTS的網絡是被禁止的,當然我們也可以把NSAllowsArbitraryLoads設置為YES禁用ATS。不過iOS 10從2017年1月1日起蘋果不允許我們通過這個方法跳過ATS,也就是說強制我們用HTTPS,如果不這樣的話提交App可能會被拒絕。但是我們可以通過NSExceptionDomains來針對特定的域名開放HTTP可以容易通過審核。

NSExceptionDomains方式 設置域。可以簡單理解成,把不支持https協議的接口設置成http的接口。

具體方法:

1、在項目的info.plist中添加一個Key:App Transport Security Settings,類型為字典類型。

2、然後給它添加一個Exception Domains,類型為字典類型;

3、把需要的支持的域添加給Exception Domains。其中域作為Key,類型為字典類型。

4、每個域下面需要設置3個屬性:NSIncludesSubdomains、NSExceptionRequiresForwardSecrecy、NSExceptionAllowsInsecureHTTPLoads。

這裡寫圖片描述 

細節提示:在iOS9以後的系統中如果使用到網絡圖片,也要注意網絡圖片是否是HTTP的哦,如果是,也要把圖片的域設置!

以iOS10 SDK編譯的工程會默認以SSL安全協議進行網絡傳輸,即HTTPS,如果依然使用HTTP協議請求網絡會報系統異常並中斷請求。目前可用如下兩種方式保持用HTTP進行網絡連接, 以下為部分是umeng給出的相應白名單,由技術人員測試各個平台所收集而來,如果有所遺漏,請自行加入:

<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>
<!-- 集成新浪微博對應的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、騰訊微博授權對應的HTTP白名單-->
<key>qq.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<!-- 騰訊授權-->
<!-- 集成人人授權對應的HTTP白名單-->
<key>renren.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<!-- 人人授權-->
<!-- 集成Facebook授權對應的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授權-->
<!-- 集成Twitter授權對應的HTTP白名單-->
<key>twitter.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/> 
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<!-- Twitter授權-->
</dict>
</dict>

隱私權限設置

iOS 10 開始對隱私權限更加嚴格,如果你不設置就會直接崩潰,現在很多遇到崩潰問題了,一般解決辦法都是在info.plist文件添加對應的Key-Value就可以了。

這裡寫圖片描述

<!-- 相冊 --> 
<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>

出現許多自己沒有添加的log日志

這裡寫圖片描述 

若控制台輸出“[] tcp_connection_xxx“等內容,可以在運行按鈕旁的選擇target選項內的 Edit Scheme - Run - Arguments - Enviroment variables中增加OS_ACTIVITY_MODE=disable,可將相關日志關閉。

解決:

打開項目, Edit Scheme 進入

這裡寫圖片描述

添加參數:

Name :OS_ACTIVITY_MODE
Value : disable

Notification

自從Notification被引入之後,蘋果就不斷的更新優化,但這些更新優化只是小打小鬧,直至現在iOS 10開始真正的進行大改重構,這讓開發者也體會到UserNotifications的易用,功能也變得非常強大。

iOS 9 以前的通知

1.在調用方法時,有些方法讓人很難區分,容易寫錯方法,這讓開發者有時候很苦惱。

2.應用在運行時和非運行時捕獲通知的路徑還不一致。

3.應用在前台時,是無法直接顯示遠程通知,還需要進一步處理。

4.已經發出的通知是不能更新的,內容發出時是不能改變的,並且只有簡單文本展示方式,擴展性根本不是很好。

iOS 10 開始的通知

1.所有相關通知被統一到了UserNotifications.framework框架中。
2.增加了撤銷、更新、中途還可以修改通知的內容。
3.通知不在是簡單的文本了,可以加入視頻、圖片,自定義通知的展示等等。
4.iOS 10相對之前的通知來說更加好用易於管理,並且進行了大規模優化,對於開發者來說是一件好事。
5.iOS 10開始對於權限問題進行了優化,申請權限就比較簡單了(本地與遠程通知集成在一個方法中)。

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

這裡寫圖片描述

注:推送的時候,開啟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 中修改應用的 Capabilities 開啟Remote notifications,請參考下圖:

這裡寫圖片描述

判斷系統版本正確方式

在你的項目中,當需要判斷系統版本的話,不要使用下面的方法:

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

它會永遠返回NO,substringToIndex:1在iOS 10 會被檢測成 iOS 1了,
應該使用下面的這些方法:

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的一部分,我們設定常熟范圍從iPhone OS 2到#define NSFoundationVersionNumber_iOS_8_4 1144.17,在iOS 10(Xcode 8)中,蘋果補充了缺少的數字,設置有未來的版本.

#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的問題(待確認)

在iOS10中,如果還使用以前設置UIStatusBar類型或者控制隱藏還是顯示的方法,會報警告,方法過期,如下圖:

這裡寫圖片描述

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

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

你必須調用父類實現awakeFromNib來給父類來執行它們需要的任何額外的初始化的機會。
雖然這種方法的默認實現不做任何事情,許多UIKit類提供非空的實現。
你可以調用自己的awakeFromNib方法中的任何時候超級實現。

XCode8新特性

證書管理

直接使用Xcode8打開工程後,你會發現你的provisonfile配置出了問題,這是由於在Xcode8中對工程配置有了一些小的改動。

在Xcode8工程配置的general選項卡中,使用更詳細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的發布,蘋果也是來了個大的跳躍,默認最低支持的iOS版本為8.0,當然也並不是說8.0以下就直接放棄了,雖然表現出來的是這樣,畢竟使用8.0以下系統的還是大有人在的,老項目要兼容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…..

跳轉 www.cnblogs.com/starainDou/p/5325643.html 下載

到這裡並沒有結束,接下來需要配置Xcode,打開以下路徑:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
,在這裡我們要改點東西,但是在這個文件夾裡的東西是鎖定的,首先右鍵‘空白部分',點擊顯示簡介,滑動到最下面,點擊小鎖打開權限,需要輸入管理員密碼,接著把所有的權限改為讀寫,第一步完成,接下來,右鍵SDKSettings.plist文件夾,和上面同樣的操作,打開讀寫權限,然後雙擊打開SDKSettings.plist文件,如圖:

這裡寫圖片描述 

在這個下面添加7.0和7.1,按照從小到大的順序排好。接著重啟電腦即可,結束的時候別忘了把剛才改的權限都改回去以防不小心動了不該動的。

看Xcode裡面:

這裡寫圖片描述 

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

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved