天天看點

iOS 10 新特性

1.語音識别 

     蘋果官方在文檔中新增了API   Speech,那麼在以前我們處理語音識别非常的繁瑣甚至很多時候可能需要借助于第三方架構處理,那麼蘋果推出了這個後,我們以後處理起來就非常的友善了,speech具有以下特點:

   可以實作連續的語音識别

   可以對語 音檔案或者語音流進行識别

   最佳化自由格式的聽寫(可了解為多語言支援)和搜尋式的字元串

官方文檔:

iOS 10 新特性
iOS 10 新特性

核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. #import <Speech/Speech.h>  
  2.     //1.建立本地化辨別符  
  3.     NSLocale *local =[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];  
  4.      //2.建立一個語音識别對象  
  5.     SFSpeechRecognizer *sf =[[SFSpeechRecognizer alloc] initWithLocale:local];  
  6.     //3.将bundle 中的資源檔案加載出來傳回一個url  
  7.     NSURL *url =[[NSBundle mainBundle] URLForResource:@"遊子吟.mp3" withExtension:nil];  
  8.     //4.将資源包中擷取的url 傳遞給 request 對象  
  9.     SFSpeechURLRecognitionRequest *res =[[SFSpeechURLRecognitionRequest alloc] initWithURL:url];  
  10.     //5.發送一個請求  
  11.     [sf recognitionTaskWithRequest:res resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {  
  12.         if (error!=nil) {  
  13.             NSLog(@"語音識别解析失敗,%@",error);  
  14.         }  
  15.         else  
  16.         {  
  17.             //解析正确  
  18.             NSLog(@"---%@",result.bestTranscription.formattedString);  
  19.         }  
  20.     }];  

2.UITabBarController 中的改進

      在iOS 10之前,tabBarItem上的文字顔色,預設是 藍色,上面的新消息提醒數字badge 預設是紅色的,未選中的TabBarItem的文字顔色預設是黑色的,我們修改的話,也隻能修改它的預設顔色 ,其它的就不能進行個性化定制,使用起來非常的不友善,iOS10之後我們可以輕松個性化定制了。

     核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. //1.建立出三個UIViewcontroller 對象  
  2.     OneViewController *oneVc =[[OneViewController alloc] init];  
  3.     //2.設定每一個控制器上的tabbar  
  4.     oneVc.view.backgroundColor =[UIColor redColor];  
  5.     //設定标題  
  6.     oneVc.tabBarItem.title = @"首頁";  
  7.     TwoViewController *twovC =[[TwoViewController alloc] init];  
  8.     twovC.view.backgroundColor =[UIColor purpleColor];  
  9.       //設定标題  
  10.     twovC.tabBarItem.title = @"圈子";  
  11.     ThreeViewController *threVC =[[ThreeViewController alloc] init];  
  12.     threVC.view.backgroundColor =[UIColor blueColor];  
  13.       //設定标題  
  14.     threVC.tabBarItem.title = @"社交";  
  15.     //2.将建立好的三個普通控制器加入到tabbarController 控制器中  
  16.     [self addChildViewController:oneVc];  
  17.     [self addChildViewController:twovC];  
  18.     [self addChildViewController:threVC];  
  19.     //改變tabbar 上面的文字預設顔色  
  20.     oneVc.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  21.         twovC.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  22.         threVC.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  23.     //使用iOS 10新推出的 修改 tabbar 未選中的tintColor 顔色  
  24.     //這一句代碼将 tabbar 未選中的時候的預設色- 黑色改為紅色  
  25.     oneVc.tabBarController.tabBar.unselectedItemTintColor =[UIColor redColor];  
  26.     //tabbarItem 中屬性  
  27.     //數字提醒的顔色  在iOS 10之前的版本預設都是數字提醒都是紅色  
  28.     oneVc.tabBarItem.badgeColor =[UIColor orangeColor];  
  29.     oneVc.tabBarItem.badgeValue =@"90";  
  30.     //将tabBarItem 中數字提醒預設的白色改掉  使用富文本修改  
  31.     [oneVc.tabBarItem setBadgeTextAttributes:@{  
  32.                                                NSForegroundColorAttributeName:[UIColor blackColor]  
  33.                                                } forState:UIControlStateNormal];  

3.iOS10.0中字型跟随系統設定變化大小

      在以前如果說我們想改變APP中程式的字型大小,我們隻能自定義字型或者使用runtime進行處理,或者都得設定UIFont,非常的不妨百年,從iOS 10蘋果官方允許我們自定義設定

   核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1.     [super viewDidLoad];  
  2.     //設定字型的改變大小  
  3.     self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];  
  4.     //允許改變  
  5.     self.labels.adjustsFontForContentSizeCategory = YES;  

4. UIViewPropertyAnimator屬性動畫器

  那麼在iOS 10之前,我們使用UIView 做動畫效果或者自定義一些layer 的動畫,如果開始了,一般無法進行停止操作更不能暫停操作,而且一些非常複雜的動畫處理也比較麻煩,但是在iOS10,蘋果退出了一個全新的API  UIViewPropertyAnimator,可供我們處理動畫操作

UIViewPropertyAnimator 是 iOS 10 中新增的一個執行 View 動畫的類,具有以下特點:

   可中斷性

   可擦除

   可反轉性

   豐富的動畫時間控制功能

官方文檔:

iOS 10 新特性
iOS 10 新特性

核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. #import "ViewController.h"  
  2. @interface ViewController ()  
  3. @property(nonatomic,strong)UIView *myView;  
  4. @property(nonatomic,strong)UIViewPropertyAnimator *myViewPro;  
  5. @end  
  6. @implementation ViewController  
  7. - (void)viewDidLoad {  
  8.     [super viewDidLoad];  
  9.     //1.建立一個View對象  
  10.     UIView *Views =[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];  
  11.     Views.backgroundColor =[UIColor yellowColor];  
  12.     [self.view addSubview:Views];  
  13.     //2.建立一個外部的變量進行引用  
  14.     self.myView = Views;  
  15.     //3.建立一個view 動畫器  
  16.     UIViewPropertyAnimator *viewPro  =[UIViewPropertyAnimator runningPropertyAnimatorWithDuration:1.0 delay:30.0 options:UIViewAnimationOptionCurveLinear animations:^{  
  17.         //使用View動畫器修改View的frame  
  18.         self.myView.frame = CGRectMake(230, 230, 130, 130);  
  19.     } completion:nil];  
  20.     self.myViewPro = viewPro;  
  21. }  
  22. //結束  
  23. - (IBAction)stop:(id)sender {  
  24.     // YES 和NO 适用于設定目前這個屬性動畫器是否可以繼續使用  
  25.     [self.myViewPro stopAnimation:YES];  
  26. }  
  27. //繼續  
  28. - (IBAction)continued:(id)sender {  
  29.     //UITimingCurveProvider  
  30.     //設定彈簧效果 DampingRatio取值範圍是 0-1  
  31.     //這個取值 決定彈簧抖動效果 的大小 ,越往  0 靠近那麼就越明顯  
  32.     UISpringTimingParameters *sp =[[UISpringTimingParameters alloc] initWithDampingRatio:0.01];  
  33.     //設定一個動畫的效果  
  34. //    UICubicTimingParameters *cub =[[UICubicTimingParameters alloc] initWithAnimationCurve:UIViewAnimationCurveEaseInOut];  
  35.      //durationFactor  給一個預設值 1就可以  
  36.     [self.myViewPro continueAnimationWithTimingParameters:sp durationFactor:1.0];  
  37. }  
  38. //暫停  
  39. - (IBAction)puase:(id)sender {  
  40.     [self.myViewPro pauseAnimation];  
  41. }  
  42. //開始  
  43. - (IBAction)start:(id)sender {  
  44.     [self.myViewPro startAnimation];  
  45. }  

5.UIColor 新增方法

   在iOS10之前,UIColor中設定顔色隻能通過RGB 來表示,在iOS原生還不支援#16進制寫法,還得自己寫分類去處理,我們知道RGB表示的顔色是優先的,而且也是不精準的,那麼在iOS10中,蘋果官方新增了colorWithDisplayP3Red方法

核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. + (  
  2. UIColor  
  3.  *)colorWithDisplayP3Red:(  
  4. CGFloat  
  5. )displayP3Red green:(  
  6. CGFloat  
  7. )green blue:(  
  8. CGFloat  
  9. )blue alpha:(  
  10. CGFloat  
  11. )alpha   
  12. NS_AVAILABLE_IOS  
  13. (  
  14. 10  
  15. _0);  

6.UIApplication對象中openUrl被廢棄

  在iOS 10.0以前的年代,我們要想使用應用程式去打開一個網頁或者進行跳轉,直接使用[[UIApplication sharedApplication] openURL 方法就可以了,但是在iOS 10 已經被廢棄了,因為使用這種方式,處理的結果我們不能攔截到也不能擷取到,對于開發是非常不利的,在iOS 10全新的退出了  [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:nil];有一個成功的回調block 可以進行監視。

  蘋果官方解釋:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. //說明在iOS 10.0中openUrl方法已經廢棄了 改為openURL:nil options:nil completionHandler:^(BOOL success  
  2.     /*  
  3.      // Options are specified in the section below for openURL options. An empty options dictionary will result in the same  
  4.      // behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather  
  5.      // than returning a result.  
  6.      // The completion handler is called on the main queue.  

關鍵代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:^(BOOL success) {  
  2.     }];  

當然除了以上的這些,其它的還有很多,比如下面這些

6. SiriKit 

在 iOS 10 裡面開發者可以使用 Siri SDK,毫無疑問這也是 iOS 10 最重要的 SDK。從此開發者可以使用原生API提供語音搜尋、語音轉文字消息甚至更多常見語音功能。

7.  User Notifications 

這個 API 讓你可以處理本地或遠端的使用者通知,并且可以基于某個條件,例如時間或者地理位置。這個異常強大,貌似可以攔截并替換自己 app 發下來的 payload,并且在之前版本SDK的本地通知架構已經被廢棄了,在上一篇文章有所講到以及代碼都有展示。

8.CallKit  

繼2014年蘋果推出VoIP證書後,這次VoIP 接口的開放,以及一個全新的 App Extension,簡直是VOIP的福音,可見蘋果對VOIP的重視。callkit架構 VoIP應用程式內建與iPhone的使用者界面,給使用者一個很棒的經曆。用這個架構來讓使用者檢視和接聽電話的鎖屏和VoIP管理聯系人電話在手機APP的收藏夾和曆史的觀點。

callkit還介紹了應用程式的擴充,使呼叫阻塞和來電識别。您可以建立一個應用程式擴充,可以将一個電話号碼與一個名稱聯系起來,或者告訴系統當一個号碼應該被阻止。

9.第三方鍵盤的改進  

   非常非常重要,第三方鍵盤一直都不能很友善的擁有長按地球鍵的功能,現在有了。通過 handleInputModeListFromView:withEvent: 可以彈出系統鍵盤清單。同時使用 documentInputMode 可以檢測輸入上下文中的語言,你可以對輸入方式進行一些類似于對齊方式的調整。

10.iOS10 對隐私權限的管理   

   比如通路的攝像頭、麥克風等硬體,都需要提前請求應用權限、允許後才可以使用,或者現在要提前聲明,雖然以往要求不嚴格。在iOS10中比如遇到崩潰,日志:

   崩潰日志:

***This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

 你需要在info.plist檔案 添加一個“NSContactsUsageDescription ”的Key,Value添加一個描述。

iOS 10 新特性

視訊播放 需要在info.Plist中配置

     官方解釋:This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSAppleMusicUsageDescription key with a string value explaining to the user how the app uses this data.

   通路使用者的隐私資料,并且沒有向使用者說明,必須在plist(info.plist)中配置這個key  NSAppleMusicUsageDescription 并且向使用者說明.

11.Xcode7 和Xcode 8項目中的xib相容問題

   在Xcode8上打開項目要小心,尤其是對于xib過程,在變動後可不要随意點儲存,否則當你回頭用Xcode7打開時時發現報錯了,Xcode儲存的xib在xcode7上是識别不了的!

12.APPlePlay(蘋果支付)

          可用于 SFSafariViewController

  可用于沒有UI的extensions中

  在 iMessage 應用中也支援 ApplePay

13.CoreData提升了并發通路性能

14.重新整理控件(UIRefresh Control)

iOS系統自帶的重新整理控件支援所有的 UIScrollView 以及其子類,比如說 UICollectionView,UITableView。

核心代碼:

[objc]  view plain  copy  print ?

iOS 10 新特性
iOS 10 新特性
  1. //  
  2. //  UIRefreshControlHosting.h  
  3. //  UIKit  
  4. //  
  5. //  Copyright 2016 Apple Inc. All rights reserved.  
  6. //  
  7. #import <Foundation/Foundation.h>  
  8. @class UIRefreshControl;  
  9. NS_CLASS_AVAILABLE_IOS(10_0) @protocol UIRefreshControlHosting <NSObject>  
  10. @property (nonatomic, strong, nullable) UIRefreshControl *refreshControl __TVOS_PROHIBITED;  
  11. @end  

15.GCD多線程支援建立私有隊列

繼續閱讀