iOS 10 與Xcode 8 新特性

iOS 10


1. 訪問權限崩潰問題

如果打開APP后點擊有關權限訪問后直接Crash了則需要在需要在info.plist文件中進行相關配置(藍牙,日歷,相機,相冊,相機,聯系人,健康等權限...)

權限配置步驟:

  1. 打開項目中的info.plist文件
  2. 在info.plist文件Add Row一行后選擇相應的權限進行添加
  3. 先去相應的Key,Value 應該可以隨便填寫
配置地方

如果一個個添加嫌麻煩可以全部添加到plist文件中



打開plist源文件后添加如

<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能訪問藍牙</string> 
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能訪問日歷</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能訪問相機</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能訪問健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能訪問健康更新 </string>
<key>NSHomeKitUsageDescription</key>
<string>App需要您的同意,才能訪問家庭 </string>
<key>NSContactsUsageDescription</key>
<string>App需要您的同意,才能訪問通訊錄 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始終訪問位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能訪問位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期間訪問位置</string>
<key>NSAppleMusicUsageDescription</key> 
<string>App需要您的同意,才能訪問媒體資料庫</string>
<key>NSMicrophoneUsageDescription</key>    
<string>App需要您的同意,才能訪問麥克風</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能訪問運動與健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能訪問相冊</string>
<key>NSRemindersUsageDescription</key>   
<string>App需要您的同意,才能訪問提醒事項</string>
<key>NSSiriUsageDescription</key>
<string>App需要您的同意,才能訪問Siri</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>App需要您的同意,才能訪問語音識別</string>
<key>NSVideoSubscriberAccountUsageDescription</key>
<string>App需要您的同意,才能訪問視頻用戶賬戶</string>```

#2. nullable報錯問題
使用Xcode8之后,需要刪除nullable否則報錯

-(void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error```

3. ATS(App Transport Security) 網絡適配問題

  1. iOS 9時,默認HTTS的網絡是被禁止的, 但可以通過向info.plist文件中添加NSAppTransportSecurity,并將NSAllowsArbitraryLoads設置為YES來禁用ATS。但是,從2017年1月1日起,所有新提交的APP默認不允許配置NSAllowsArbitraryLoads來繞過ATS的限制,所以你的APP應盡早使用HTTPS進行內容訪問,以避免APP被拒絕風險。
  2. 如果APP中如果集成了第三方的SDK,則可以通過NSAppTransportSecurity中NSExceptionDomains設置白名單的方式對特定的域名開放HTTP內容來通過審核。
    NSExceptionDomains設置方法
  3. 在NSAppTransportSecurity 中新加入了NSAllowsArbitraryLoadsInWebContent鍵,允許任意web頁面加載,同時蘋果會用 ATS 來保護你的app。

4.新增UIViewPropertyAnimator類

類特點:

1.可中斷性
2.可擦除
3.可反轉性
4.豐富的動畫時間控制功能

//初始化屬性動畫器
UIViewPropertyAnimator *viewPropertyAnimator = [[UIViewPropertyAnimator alloc] initWithDuration:5.f curve:UIViewAnimationCurveLinear animations:^{
    [self.view setAlpha:0.3];
}];
[viewPropertyAnimator startAnimation];

5.Notification(通知)

  • 所有相關通知被統一到了UserNotifications.framework框架中。
  • 增加了撤銷、更新、中途還可以修改通知的內容。
  • 通知中可以加入視頻、圖片,自定義通知的展示等等。
  • 相對之前的通知來說更加好用易于管理,并且進行了大規模優化。
  • 對于權限問題進行了優化,申請權限就比較簡單了(本地與遠程通知集成在一個方法中)。
    通知相關參考

6.UIStatusBar方法過期

過期方法:

// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;```
新方法:

if UIKIT_DEFINE_AS_PROPERTIES

@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
// 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.
@property(nonatomic, readonly) UIStatusBarAnimation preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarAnimationFade

else

  • (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

endif```

上面這個新方法在UIViewController.h文件中,只需要在viewController里調用即可。

- (BOOL)prefersStatusBarHidden{ 
  return YES;
}

- (UIStatusBarStyle)preferredStatusBarStyle{  
  return UIStatusBarStyleDefault;
}```

##7.插件取消
Xcode8取消了三方插件的功能,好多教程破解可以繼續使用,但是可能app上線可能會被拒。

#Xcode 8 
---
Xcode 8 可以創建iPhone,iPad,Apple Watch,Mac,Apple TV 等平臺的應用程序。

![Xcode 8 首界面](http://upload-images.jianshu.io/upload_images/2529977-c4a3f37cef2c061e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##1. Swift 3
Swift 3對大量語法進行了優化及更新,會對Swift 3以前的版本會有影響,為解決此問題Xcode 8在編譯設置中支持開發者選擇Swift 2或Swift 2.3 進行編譯。
如果一個目標(Target)需要支持Swift 2.3, 需要在目標(Target)的編譯設置里把Use Legacy Swift Language Version 設置成Yes
![支持Swift語言以往版本](http://upload-images.jianshu.io/upload_images/2529977-6b613df856043023.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##2. 證書管理
Xcode 8添加了自動管理證書功能。
建議勾選這個選項Automatically manage signing
如未設置開發者賬號,則需要在xcode->preferences->Accounts中添加

![自動管理證書](http://upload-images.jianshu.io/upload_images/2529977-81d200dcecac3fa6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


#Xcode 8問題解決
---
##1. 代碼注釋快捷功能不能使用
解決方法
打開終端 - 輸入命令運行:sudo /usr/libexec/xpccachectl
重啟計算機

##2. 出現雜亂的Debug
會在Debug窗口出現如下信息
>2016-10-10 16:12:37.746003 HHRouterExample[9121:339626] 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, privacy_setting: 2, enable_private_data: 0

屏蔽方法
選擇Product-> Scheme -> Edit Scheme -> Run -> Arguments 然后在Environment Variables里添加`OS_ACTIVITY_MODE = Disable`
![屏蔽方法](http://upload-images.jianshu.io/upload_images/2529977-df319775614e7154.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##官方鏈接地址
---
[UserNotifications](https://developer.apple.com/reference/usernotifications)
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 因為要結局swift3.0中引用snapKit的問題,看到一篇介紹Xcode8,swift3變化的文章,覺得很詳細...
    uniapp閱讀 4,536評論 0 12
  • iOS6新特性 一、關于內存警告 ios6中廢除了viewDidUnload,viewWillUnload這兩個系...
    Jimmy_P閱讀 2,236評論 3 29
  • 發現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,252評論 4 61
  • 今天我們上了主題為“節日”的班會,達成一個共識:無論是中國的還是外國的節日,無論它的由來是什么,無論是怎樣的慶祝方...
    常星慧閱讀 257評論 0 0
  • 1. 以前的一個學生A,畢業前找了一個單位實習,干了不到一個月辭職了,她來找我的時候,還帶著一臉憤憤不平的表情。 ...
    不辣的媽閱讀 335評論 0 2