1.語音識别
蘋果官方在文檔中新增了API Speech,那麼在以前我們處理語音識别非常的繁瑣甚至很多時候可能需要借助于第三方架構處理,那麼蘋果推出了這個後,我們以後處理起來就非常的友善了,speech具有以下特點:
可以實作連續的語音識别
可以對語 音檔案或者語音流進行識别
最佳化自由格式的聽寫(可了解為多語言支援)和搜尋式的字元串
官方文檔:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5iM4kDNzETOwQDOzIjN2QTMvwFOxYDM2EDMy8CXldWYtl2LcRWYvxGc19CXwhGcvwlcvRXakVWdvwVbvNmL0lGMyUjLzJmYvw1LcpDc0RHaiojIsJye.png)
核心代碼:
[objc] view plain copy print ?
- #import <Speech/Speech.h>
- //1.建立本地化辨別符
- NSLocale *local =[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
- //2.建立一個語音識别對象
- SFSpeechRecognizer *sf =[[SFSpeechRecognizer alloc] initWithLocale:local];
- //3.将bundle 中的資源檔案加載出來傳回一個url
- NSURL *url =[[NSBundle mainBundle] URLForResource:@"遊子吟.mp3" withExtension:nil];
- //4.将資源包中擷取的url 傳遞給 request 對象
- SFSpeechURLRecognitionRequest *res =[[SFSpeechURLRecognitionRequest alloc] initWithURL:url];
- //5.發送一個請求
- [sf recognitionTaskWithRequest:res resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
- if (error!=nil) {
- NSLog(@"語音識别解析失敗,%@",error);
- }
- else
- {
- //解析正确
- NSLog(@"---%@",result.bestTranscription.formattedString);
- }
- }];
2.UITabBarController 中的改進
在iOS 10之前,tabBarItem上的文字顔色,預設是 藍色,上面的新消息提醒數字badge 預設是紅色的,未選中的TabBarItem的文字顔色預設是黑色的,我們修改的話,也隻能修改它的預設顔色 ,其它的就不能進行個性化定制,使用起來非常的不友善,iOS10之後我們可以輕松個性化定制了。
核心代碼:
[objc] view plain copy print ?
- //1.建立出三個UIViewcontroller 對象
- OneViewController *oneVc =[[OneViewController alloc] init];
- //2.設定每一個控制器上的tabbar
- oneVc.view.backgroundColor =[UIColor redColor];
- //設定标題
- oneVc.tabBarItem.title = @"首頁";
- TwoViewController *twovC =[[TwoViewController alloc] init];
- twovC.view.backgroundColor =[UIColor purpleColor];
- //設定标題
- twovC.tabBarItem.title = @"圈子";
- ThreeViewController *threVC =[[ThreeViewController alloc] init];
- threVC.view.backgroundColor =[UIColor blueColor];
- //設定标題
- threVC.tabBarItem.title = @"社交";
- //2.将建立好的三個普通控制器加入到tabbarController 控制器中
- [self addChildViewController:oneVc];
- [self addChildViewController:twovC];
- [self addChildViewController:threVC];
- //改變tabbar 上面的文字預設顔色
- oneVc.tabBarController.tabBar.tintColor =[UIColor yellowColor];
- twovC.tabBarController.tabBar.tintColor =[UIColor yellowColor];
- threVC.tabBarController.tabBar.tintColor =[UIColor yellowColor];
- //使用iOS 10新推出的 修改 tabbar 未選中的tintColor 顔色
- //這一句代碼将 tabbar 未選中的時候的預設色- 黑色改為紅色
- oneVc.tabBarController.tabBar.unselectedItemTintColor =[UIColor redColor];
- //tabbarItem 中屬性
- //數字提醒的顔色 在iOS 10之前的版本預設都是數字提醒都是紅色
- oneVc.tabBarItem.badgeColor =[UIColor orangeColor];
- oneVc.tabBarItem.badgeValue =@"90";
- //将tabBarItem 中數字提醒預設的白色改掉 使用富文本修改
- [oneVc.tabBarItem setBadgeTextAttributes:@{
- NSForegroundColorAttributeName:[UIColor blackColor]
- } forState:UIControlStateNormal];
3.iOS10.0中字型跟随系統設定變化大小
在以前如果說我們想改變APP中程式的字型大小,我們隻能自定義字型或者使用runtime進行處理,或者都得設定UIFont,非常的不妨百年,從iOS 10蘋果官方允許我們自定義設定
核心代碼:
[objc] view plain copy print ?
- [super viewDidLoad];
- //設定字型的改變大小
- self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
- //允許改變
- self.labels.adjustsFontForContentSizeCategory = YES;
4. UIViewPropertyAnimator屬性動畫器
那麼在iOS 10之前,我們使用UIView 做動畫效果或者自定義一些layer 的動畫,如果開始了,一般無法進行停止操作更不能暫停操作,而且一些非常複雜的動畫處理也比較麻煩,但是在iOS10,蘋果退出了一個全新的API UIViewPropertyAnimator,可供我們處理動畫操作
UIViewPropertyAnimator 是 iOS 10 中新增的一個執行 View 動畫的類,具有以下特點:
可中斷性
可擦除
可反轉性
豐富的動畫時間控制功能
官方文檔:
核心代碼:
[objc] view plain copy print ?
- #import "ViewController.h"
- @interface ViewController ()
- @property(nonatomic,strong)UIView *myView;
- @property(nonatomic,strong)UIViewPropertyAnimator *myViewPro;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- //1.建立一個View對象
- UIView *Views =[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
- Views.backgroundColor =[UIColor yellowColor];
- [self.view addSubview:Views];
- //2.建立一個外部的變量進行引用
- self.myView = Views;
- //3.建立一個view 動畫器
- UIViewPropertyAnimator *viewPro =[UIViewPropertyAnimator runningPropertyAnimatorWithDuration:1.0 delay:30.0 options:UIViewAnimationOptionCurveLinear animations:^{
- //使用View動畫器修改View的frame
- self.myView.frame = CGRectMake(230, 230, 130, 130);
- } completion:nil];
- self.myViewPro = viewPro;
- }
- //結束
- - (IBAction)stop:(id)sender {
- // YES 和NO 适用于設定目前這個屬性動畫器是否可以繼續使用
- [self.myViewPro stopAnimation:YES];
- }
- //繼續
- - (IBAction)continued:(id)sender {
- //UITimingCurveProvider
- //設定彈簧效果 DampingRatio取值範圍是 0-1
- //這個取值 決定彈簧抖動效果 的大小 ,越往 0 靠近那麼就越明顯
- UISpringTimingParameters *sp =[[UISpringTimingParameters alloc] initWithDampingRatio:0.01];
- //設定一個動畫的效果
- // UICubicTimingParameters *cub =[[UICubicTimingParameters alloc] initWithAnimationCurve:UIViewAnimationCurveEaseInOut];
- //durationFactor 給一個預設值 1就可以
- [self.myViewPro continueAnimationWithTimingParameters:sp durationFactor:1.0];
- }
- //暫停
- - (IBAction)puase:(id)sender {
- [self.myViewPro pauseAnimation];
- }
- //開始
- - (IBAction)start:(id)sender {
- [self.myViewPro startAnimation];
- }
5.UIColor 新增方法
在iOS10之前,UIColor中設定顔色隻能通過RGB 來表示,在iOS原生還不支援#16進制寫法,還得自己寫分類去處理,我們知道RGB表示的顔色是優先的,而且也是不精準的,那麼在iOS10中,蘋果官方新增了colorWithDisplayP3Red方法
核心代碼:
[objc] view plain copy print ?
- + (
- UIColor
- *)colorWithDisplayP3Red:(
- CGFloat
- )displayP3Red green:(
- CGFloat
- )green blue:(
- CGFloat
- )blue alpha:(
- CGFloat
- )alpha
- NS_AVAILABLE_IOS
- (
- 10
- _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.0中openUrl方法已經廢棄了 改為openURL:nil options:nil completionHandler:^(BOOL success
- /*
- // Options are specified in the section below for openURL options. An empty options dictionary will result in the same
- // behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather
- // than returning a result.
- // The completion handler is called on the main queue.
關鍵代碼:
[objc] view plain copy print ?
- [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:^(BOOL success) {
- }];
當然除了以上的這些,其它的還有很多,比如下面這些
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添加一個描述。
視訊播放 需要在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 ?
- //
- // UIRefreshControlHosting.h
- // UIKit
- //
- // Copyright 2016 Apple Inc. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @class UIRefreshControl;
- NS_CLASS_AVAILABLE_IOS(10_0) @protocol UIRefreshControlHosting <NSObject>
- @property (nonatomic, strong, nullable) UIRefreshControl *refreshControl __TVOS_PROHIBITED;
- @end
15.GCD多線程支援建立私有隊列