Xcode8新特性

注釋問題解決

這個(gè)是因?yàn)樘O果解決xcode ghost。把插件屏蔽了。解決方法
命令運(yùn)行: sudo /usr/libexec/xpccachectl
然后必須重啟電腦后生效

一.代碼及Api注意
使用Xcode8之后,有些代碼可能就編譯不過去了,具體我就說說我碰到的問題。1.UIWebView的代理方法:**注意要?jiǎng)h除NSError前面的 nullable,否則報(bào)錯(cuò)。

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

二。權(quán)限以及相關(guān)設(shè)置
注意,添加的時(shí)候,末尾不要有空格我們需要打開info.plist文件添加相應(yīng)權(quán)限的說明,否則程序在iOS10上會出現(xiàn)崩潰。具體如下圖:

添加的權(quán)限設(shè)置 ![Uploading 707724-e81adf182229475f_643270.png . . .] .png

麥克風(fēng)權(quán)限:Privacy - Microphone Usage Description 是否允許此App使用你的麥克風(fēng)?相機(jī)權(quán)限: Privacy - Camera Usage Description 是否允許此App使用你的相機(jī)?相冊權(quán)限: Privacy - Photo Library Usage Description 是否允許此App訪問你的媒體資料庫?通訊錄權(quán)限: Privacy - Contacts Usage Description 是否允許此App訪問你的通訊錄?藍(lán)牙權(quán)限:Privacy - Bluetooth Peripheral Usage Description 是否許允此App使用藍(lán)牙?
語音轉(zhuǎn)文字權(quán)限:Privacy - Speech Recognition Usage Description 是否允許此App使用語音識別?日歷權(quán)限:Privacy - Calendars Usage Description 是否允許此App使用日歷?
定位權(quán)限:Privacy - Location When In Use Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關(guān)數(shù)據(jù)定位權(quán)限: Privacy - Location Always Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關(guān)數(shù)據(jù)定位的需要這么寫,防止上架被拒。
三。更新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打印雜亂.png

如果寫了之后還是打印log,請重新勾選對勾,就可以解決了

四。Notification(通知)
自從Notification
被引入之后,蘋果就不斷的更新優(yōu)化,但這些更新優(yōu)化只是小打小鬧,直至現(xiàn)在iOS 10開始真正的進(jìn)行大改重構(gòu),這讓開發(fā)者也體會到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)用在前臺時(shí),是無法直接顯示遠(yuǎn)程通知,還需要進(jìn)一步處理。
4.已經(jīng)發(fā)出的通知是不能更新的,內(nèi)容發(fā)出時(shí)是不能改變的,并且只有簡單文本展示方式,擴(kuò)展性根本不是很好。

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

iOS 10 通知學(xué)習(xí)相關(guān)資料:
UserNotifications: 蘋果官方文檔 - 蘋果官方視頻1 - 蘋果官方視頻2 - 蘋果官方視頻3活久見的重構(gòu) - iOS 10 UserNotifications 框架解析WWDC2016 Session筆記 - iOS 10 推送Notification新特性

五。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可能會被拒絕。但是我們可以通過NSExceptionDomains
來針對特定的域名開放HTTP
可以容易通過審核。
參考學(xué)習(xí)文章如下:關(guān)于 iOS 10 中 ATS 的問題
六。iOS 10 UICollectionView 性能優(yōu)化
隨著開發(fā)者對UICollectionView
的信賴,項(xiàng)目中用的地方也比較多,但是還是存在一些問題,比如有時(shí)會卡頓、加載慢等。所以iOS 10 對UICollectionView
進(jìn)一步的優(yōu)化,因?yàn)閿⑹銎饋肀容^復(fù)雜耗費(fèi)時(shí)間,在這里只提供學(xué)習(xí)參考文章如下: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.

因?yàn)橹拔覀兌际怯肦GB
來設(shè)置顏色,反正用起來也不是特別多樣化,這次新增的方法應(yīng)該就是一個(gè)彌補(bǔ)吧。所以在iOS 10 蘋果官方建議我們使用sRGB
,因?yàn)樗阅芨茫矢S富。如果你自己為UIColor
寫了一套分類的話也可嘗試替換為sRGB
,UIColor
類中新增了兩個(gè)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 10UITextField
添加了textContentType
枚舉,指示文本輸入?yún)^(qū)域所期望的語義意義。
使用此屬性可以給鍵盤和系統(tǒng)信息,關(guān)于用戶輸入的內(nèi)容的預(yù)期的語義意義。例如,您可以指定一個(gè)文本字段,用戶填寫收到一封電子郵件確認(rèn)uitextcontenttypeemailaddress
。當(dāng)您提供有關(guān)您期望用戶在文本輸入?yún)^(qū)域中輸入的內(nèi)容的信息時(shí),系統(tǒng)可以在某些情況下自動選擇適當(dāng)?shù)逆I盤,并提高鍵盤修正和主動與其他文本輸入機(jī)會的整合。
九.iOS 10 字體隨著手機(jī)系統(tǒng)字體而改變
當(dāng)我們手機(jī)系統(tǒng)字體改變了之后,那我們App
的label
也會跟著一起變化,這需要我們寫很多代碼來進(jìn)一步處理才能實(shí)現(xiàn),但是iOS 10 提供了這樣的屬性adjustsFontForContentSizeCategory
來設(shè)置。因?yàn)闆]有真機(jī),具體實(shí)際操作還沒去實(shí)現(xiàn),如果理解錯(cuò)誤幫忙指正。
UILabel myLabel = [UILabel new]; / UIFont 的preferredFontForTextStyle: 意思是指定一個(gè)樣式,并讓字體大小符合用戶設(shè)定的字體大小。 / 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

2353624-66e424afef858b14.png

iOS 10 以后只要是繼承UIScrollView
那么就支持刷新功能:
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;

11.iOS 10 判斷系統(tǒng)版本正確姿勢
判斷系統(tǒng)版本是我們經(jīng)常用到的,尤其是現(xiàn)在大家都有可能需要適配iOS 10,那么問題就出現(xiàn)了,如下圖:

2353624-76e927957e4c8428.png

我們得到了答案是:

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

所以說判斷系統(tǒng)方法最好還是用后面的兩種方法,哦~我忘記說了[[UIDevice currentDevice] systemVersion].floatValue
這個(gè)方法也是不靠譜的,好像在8.3
版本輸出的值是8.2
,記不清楚了反正是不靠譜的,所以建議大家用[[UIDevice currentDevice] systemVersion]
這個(gè)方法!
文章來源
參考文章

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容