iOS 10 新特性以及xcode8

一.代碼及Api注意ios

使用Xcode8以後,有些代碼可能就編譯不過去了,具體我就說說我碰到的問題。
1.UIWebView的代理方法:
**注意要刪除NSError前面的 nullable,不然報錯。web

- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error { [self hideHud]; }

二。權限以及相關設置性能優化

注意,添加的時候,末尾不要有空格
咱們須要打開info.plist文件添加相應權限的說明,不然程序在iOS10上會出現崩潰。
具體以下圖:網絡


QQ20160914-0.png

麥克風權限:Privacy - Microphone Usage Description 是否容許此App使用你的麥克風?
相機權限: Privacy - Camera Usage Description 是否容許此App使用你的相機?
相冊權限: Privacy - Photo Library Usage Description 是否容許此App訪問你的媒體資料庫?通信錄權限: Privacy - Contacts Usage Description 是否容許此App訪問你的通信錄?
藍牙權限:Privacy - Bluetooth Peripheral Usage Description 是否許允此App使用藍牙?app

語音轉文字權限:Privacy - Speech Recognition Usage Description 是否容許此App使用語音識別?
日曆權限:Privacy - Calendars Usage Description 是否容許此App使用日曆?框架

定位權限:Privacy - Location When In Use Usage Description 咱們須要經過您的地理位置信息獲取您周邊的相關數據
定位權限: Privacy - Location Always Usage Description 咱們須要經過您的地理位置信息獲取您周邊的相關數據
定位的須要這麼寫,防止上架被拒。ide


三。更新Xcode8以後,新創建工程,都會打印一堆莫名其妙看不懂的Log.性能

如這些學習

subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1,

屏蔽的方法以下:
Xcode8裏邊 Edit Scheme-> Run -> Arguments, 在Environment Variables裏邊添加
OS_ACTIVITY_MODE = Disable 字體


若是寫了以後仍是打印log,請從新勾選對勾,就能夠解決了

 

四。Notification(通知)

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

  • iOS 9 之前的通知

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

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

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

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

  • iOS 10 開始的通知

    1.全部相關通知被統一到了UserNotifications.framework框架中。

    2.增長了撤銷、更新、中途還能夠修改通知的內容。

    3.通知不在是簡單的文本了,能夠加入視頻、圖片,自定義通知的展現等等。

    4.iOS 10相對以前的通知來講更加好用易於管理,而且進行了大規模優化,對於開發者來講是一件好事。

    5.iOS 10開始對於權限問題進行了優化,申請權限就比較簡單了(本地與遠程通知集成在一個方法中)。

  • iOS 10 通知學習相關資料:

    UserNotifications: 蘋果官方文檔 - 蘋果官方視頻1 - 蘋果官方視頻2 - 蘋果官方視頻3
    活久見的重構 - iOS 10 UserNotifications 框架解析
    WWDC2016 Session筆記 - iOS 10 推送Notification新特性


五。ATS的問題

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

參考學習文章以下:
關於 iOS 10 中 ATS 的問題

六。iOS 10 UICollectionView 性能優化

隨着開發者對UICollectionView的信賴,項目中用的地方也比較多,可是仍是存在一些問題,好比有時會卡頓、加載慢等。因此iOS 10 對UICollectionView進一步的優化,由於敘述起來比較複雜耗費時間,在這裏只提供學習參考文章以下:
WWDC2016 Session筆記 - iOS 10 UICollectionView新特性

 

七.iOS 10 UIColor 新增方法

如下是官方文檔的說明:

Most graphics frameworks throughout the system, including Core Graphics, Core Image, Metal, and AVFoundation, have substantially improved support for extended-range pixel formats and wide-gamut color spaces. By extending this behavior throughout the entire graphics stack, it is easier than ever to support devices with a wide color display. In addition, UIKit standardizes on working in a new extended sRGB color space, making it easy to mix sRGB colors with colors in other, wider color gamuts without a significant performance penalty.

Here are some best practices to adopt as you start working with Wide Color.

  • In iOS 10, the UIColor class uses the extended sRGB color space and its initializers no longer clamp raw component values to between 0.0 and 1.0. If your app relies on UIKit to clamp component values (whether you’re creating a color or asking a color for its component values), you need to change your app’s behavior when you link against iOS 10.
  • When performing custom drawing in a UIView on an iPad Pro (9.7 inch), the underlying drawing environment is configured with an extended sRGB color space.
  • If your app renders custom image objects, use the new UIGraphicsImageRenderer class to control whether the destination bitmap is created using an extended-range or standard-range format.
  • If you are performing your own image processing on wide-gamut devices using a lower level API, such as Core Graphics or Metal, you should use an extended range color space and a pixel format that supports 16-bit floating-point component values. When clamping of color values is necessary, you should do so explicitly.
  • Core Graphics, Core Image, and Metal Performance Shaders provide new options for easily converting colors and images between color spaces.

由於以前咱們都是用RGB來設置顏色,反正用起來也不是特別多樣化,此次新增的方法應該就是一個彌補吧。因此在iOS 10 蘋果官方建議咱們使用sRGB,由於它性能更好,色彩更豐富。若是你本身爲UIColor寫了一套分類的話也可嘗試替換爲sRGBUIColor類中新增了兩個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);

八.iOS 10 UITextContentType

// The textContentType property is to provide the keyboard with extra information about the semantic intent of the text document. @property(nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil

在iOS 10 UITextField添加了textContentType枚舉,指示文本輸入區域所指望的語義意義。

使用此屬性能夠給鍵盤和系統信息,關於用戶輸入的內容的預期的語義意義。例如,您能夠指定一個文本字段,用戶填寫收到一封電子郵件確認uitextcontenttypeemailaddress。當您提供有關您指望用戶在文本輸入區域中輸入的內容的信息時,系統能夠在某些狀況下自動選擇適當的鍵盤,並提升鍵盤修正和主動與其餘文本輸入機會的整合。

九.iOS 10 字體隨着手機系統字體而改變

當咱們手機系統字體改變了以後,那咱們Applabel也會跟着一塊兒變化,這須要咱們寫不少代碼來進一步處理才能實現,可是iOS 10 提供了這樣的屬性adjustsFontForContentSizeCategory來設置。由於沒有真機,具體實際操做還沒去實現,若是理解錯誤幫忙指正。

UILabel *myLabel = [UILabel new]; /* UIFont 的preferredFontForTextStyle: 意思是指定一個樣式,並讓字體大小符合用戶設定的字體大小。 */ myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline]; /* Indicates whether the corresponding element should automatically update its font when the device’s UIContentSizeCategory is changed. For this property to take effect, the element’s font must be a font vended using +preferredFontForTextStyle: or +preferredFontForTextStyle:compatibleWithTraitCollection: with a valid UIFontTextStyle. */ //是否更新字體的變化 myLabel.adjustsFontForContentSizeCategory = YES;

十.iOS 10 UIScrollView新增refreshControl


 

iOS 10 之後只要是繼承UIScrollView那麼就支持刷新功能:

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;

11.iOS 10 判斷系統版本正確姿式

判斷系統版本是咱們常常用到的,尤爲是如今你們都有可能須要適配iOS 10,那麼問題就出現了,以下圖:


 

咱們獲得了答案是:

//值爲 1 [[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue] //值爲10.000000 [[UIDevice currentDevice] systemVersion].floatValue, //值爲10.0 [[UIDevice currentDevice] systemVersion]

因此說判斷系統方法最好仍是用後面的兩種方法,哦~我忘記說了[[UIDevice currentDevice] systemVersion].floatValue這個方法也是不靠譜的,好像在8.3版本輸出的值是8.2,記不清楚了反正是不靠譜的,因此建議你們用[[UIDevice currentDevice] systemVersion]這個方法!

相關文章
相關標籤/搜索