iOS 10 新特性

来源:互联网 发布:淘宝不发货投诉 编辑:程序博客网 时间:2024/05/04 10:34

1.语音识别 

     苹果官方在文档中新增了API   Speech,那么在以前我们处理语音识别非常的繁琐甚至很多时候可能需要借助于第三方框架处理,那么苹果推出了这个后,我们以后处理起来就非常的方便了,speech具有以下特点:

   可以实现连续的语音识别

   可以对语 音文件或者语音流进行识别

   最佳化自由格式的听写(可理解为多语言支持)和搜索式的字符串

官方文档:

  Snip20160618_28.png


Snip20160618_29.png

核心代码:

[objc] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.        
  7.     //3.将bundle 中的资源文件加载出来返回一个url  
  8.        
  9.     NSURL *url =[[NSBundle mainBundle] URLForResource:@"游子吟.mp3" withExtension:nil];  
  10.     //4.将资源包中获取的url 传递给 request 对象  
  11.     SFSpeechURLRecognitionRequest *res =[[SFSpeechURLRecognitionRequest alloc] initWithURL:url];  
  12.        
  13.     //5.发送一个请求  
  14.     [sf recognitionTaskWithRequest:res resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {  
  15.         if (error!=nil) {  
  16.             NSLog(@"语音识别解析失败,%@",error);  
  17.         }  
  18.         else  
  19.         {  
  20.             //解析正确  
  21.             NSLog(@"---%@",result.bestTranscription.formattedString);  
  22.         }  
  23.     }];  

 /**

     语音识别同样的需要真机进行测试 ,因为需要硬件的支持,还需要访问权限

     ***/


2.UITabBarController 中的改进

      在iOS 10之前,tabBarItem上的文字颜色,默认是 蓝色,上面的新消息提醒数字badge 默认是红色的,未选中的TabBarItem的文字颜色默认是黑色的,我们修改的话,也只能修改它的默认颜色 ,其它的就不能进行个性化定制,使用起来非常的不方便,iOS10之后我们可以轻松个性化定制了。

     核心代码:

[objc] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. //1.创建出三个UIViewcontroller 对象  
  2.        
  3.     OneViewController *oneVc =[[OneViewController alloc] init];  
  4.        
  5.     //2.设置每一个控制器上的tabbar  
  6.     oneVc.view.backgroundColor =[UIColor redColor];  
  7.        
  8.      
  9.        
  10.        
  11.     //设置标题  
  12.     oneVc.tabBarItem.title = @"首页";  
  13.        
  14.        
  15.        
  16.     TwoViewController *twovC =[[TwoViewController alloc] init];  
  17.        
  18.     twovC.view.backgroundColor =[UIColor purpleColor];  
  19.        
  20.        
  21.       //设置标题  
  22.     twovC.tabBarItem.title = @"圈子";  
  23.     ThreeViewController *threVC =[[ThreeViewController alloc] init];  
  24.     threVC.view.backgroundColor =[UIColor blueColor];  
  25.        
  26.       //设置标题  
  27.     threVC.tabBarItem.title = @"社交";  
  28.        
  29.        
  30.     //2.将创建好的三个普通控制器加入到tabbarController 控制器中  
  31.        
  32.     [self addChildViewController:oneVc];  
  33.        
  34.     [self addChildViewController:twovC];  
  35.     [self addChildViewController:threVC];  
  36.        
  37.        
  38.        
  39.     //改变tabbar 上面的文字默认颜色  
  40.        
  41.     oneVc.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  42.        
  43.         twovC.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  44.        
  45.         threVC.tabBarController.tabBar.tintColor =[UIColor yellowColor];  
  46.        
  47.        
  48.     //使用iOS 10新推出的 修改 tabbar 未选中的tintColor 颜色  
  49.        
  50.     //这一句代码将 tabbar 未选中的时候的默认色- 黑色改为红色  
  51.        
  52.     oneVc.tabBarController.tabBar.unselectedItemTintColor =[UIColor redColor];  
  53.        
  54.        
  55.     //tabbarItem 中属性  
  56.        
  57.     //数字提醒的颜色  在iOS 10之前的版本默认都是数字提醒都是红色  
  58.     oneVc.tabBarItem.badgeColor =[UIColor orangeColor];  
  59.     oneVc.tabBarItem.badgeValue =@"90";  
  60.        
  61.     //将tabBarItem 中数字提醒默认的白色改掉  使用富文本修改  
  62.     [oneVc.tabBarItem setBadgeTextAttributes:@{  
  63.                                                NSForegroundColorAttributeName:[UIColor blackColor]  
  64.                                                } forState:UIControlStateNormal];  

3.iOS10.0中字体跟随系统设置变化大小


      在以前如果说我们想改变APP中程序的字体大小,我们只能自定义字体或者使用runtime进行处理,或者都得设置UIFont,非常的不妨百年,从iOS 10苹果官方允许我们自定义设置

   核心代码:

[objc] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. /* 
  2.       在iOS 10当中,当咱们用户将手机的字体大小进行了设置调整之后,那么app中设置相关代码字体也会跟着一起变化 ,支持常见一些字体UI控件 比如uilabel uibutton 
  3.      **/  
  4.     [super viewDidLoad];  
  5.        
  6.     //设置字体的改变大小  
  7.     self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];  
  8.     //允许改变  
  9.        
  10.     /* 
  11.        苹果官方明确的告诉你必须和  preferredFontForTextStyle 或者preferredFontForTextStyle:(NSString *)style compatibleWithTraitCollection 进行结合使用 
  12.        注意这里不支持模拟器操作 
  13.      **/  
  14.        
  15.     self.labels.adjustsFontForContentSizeCategory = YES;  

4. UIViewPropertyAnimator属性动画器


  那么在iOS 10之前,我们使用UIView 做动画效果或者自定义一些layer 的动画,如果开始了,一般无法进行停止操作更不能暂停操作,而且一些非常复杂的动画处理也比较麻烦,但是在iOS10,苹果退出了一个全新的API  UIViewPropertyAnimator,可供我们处理动画操作


UIViewPropertyAnimator 是 iOS 10 中新增的一个执行 View 动画的类,具有以下特点:

   可中断性

   可擦除

   可反转性

   丰富的动画时间控制功能

官方文档:

   Snip20160618_30.png

Snip20160618_31.png

核心代码:

[objc] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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.        
  10.     //1.创建一个View对象  
  11.     UIView *Views =[[UIView alloc] initWithFrame:CGRectMake(5050100100)];  
  12.     Views.backgroundColor =[UIColor yellowColor];  
  13.     [self.view addSubview:Views];  
  14.     //2.创建一个外部的变量进行引用  
  15.        
  16.     self.myView = Views;  
  17.        
  18.        
  19.     //3.创建一个view 动画器  
  20.     UIViewPropertyAnimator *viewPro  =[UIViewPropertyAnimator runningPropertyAnimatorWithDuration:1.0 delay:30.0 options:UIViewAnimationOptionCurveLinear animations:^{  
  21.         //使用View动画器修改View的frame  
  22.         self.myView.frame = CGRectMake(230230130130);  
  23.     } completion:nil];  
  24.        
  25.     self.myViewPro = viewPro;  
  26. }  
  27. //结束  
  28. - (IBAction)stop:(id)sender {  
  29.        
  30.     // YES 和NO 适用于设置当前这个属性动画器是否可以继续使用  
  31.     [self.myViewPro stopAnimation:YES];  
  32. }  
  33. //继续  
  34. - (IBAction)continued:(id)sender {  
  35.        
  36.        
  37.     //UITimingCurveProvider  
  38.     /** 
  39.     @property(nullable, nonatomic, readonly) UICubicTimingParameters *cubicTimingParameters; 
  40.     @property(nullable, nonatomic, readonly) UISpringTimingParameters *springTimingParameters; 
  41.        
  42.      **/  
  43.     //设置弹簧效果 DampingRatio取值范围是 0-1  
  44.        
  45.     //这个取值 决定弹簧抖动效果 的大小 ,越往  0 靠近那么就越明显  
  46.     UISpringTimingParameters *sp =[[UISpringTimingParameters alloc] initWithDampingRatio:0.01];  
  47.        
  48.     //设置一个动画的效果  
  49. //    UICubicTimingParameters *cub =[[UICubicTimingParameters alloc] initWithAnimationCurve:UIViewAnimationCurveEaseInOut];  
  50.        
  51.      //durationFactor  给一个默认值 1就可以  
  52.     [self.myViewPro continueAnimationWithTimingParameters:sp durationFactor:1.0];  
  53. }  
  54. //暂停  
  55. - (IBAction)puase:(id)sender {  
  56.        
  57.     [self.myViewPro pauseAnimation];  
  58. }  
  59. //开始  
  60. - (IBAction)start:(id)sender {  
  61.        
  62.     [self.myViewPro startAnimation];  
  63. }  

5.UIColor 新增方法


   在iOS10之前,UIColor中设置颜色只能通过RGB 来表示,在iOS原生还不支持#16进制写法,还得自己写分类去处理,我们知道RGB表示的颜色是优先的,而且也是不精准的,那么在iOS10中,苹果官方新增了colorWithDisplayP3Red方法

核心代码:

[objc] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  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?在CODE上查看代码片派生到我的代码片
  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?在CODE上查看代码片派生到我的代码片
  1. [[UIApplication sharedApplication] openURL:nil options:nil completionHandler:^(BOOL success) {  
  2.            
  3.     }];  


当然除了以上的这些,其它的还有很多,比如下面这些


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添加一个描述。

ssss.png

视频播放 需要在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?在CODE上查看代码片派生到我的代码片
  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 (nonatomicstrong, nullable) UIRefreshControl *refreshControl __TVOS_PROHIBITED;  
  11. @end  

15.GCD多线程支持创建私有队列
0 0
原创粉丝点击