iOS10开发的最新知识和心得体会

  那么在前两天个人Xcode 8.0新特性和iOS10.0开发分享后,短短的时间吸引了不少粉丝,因而我更加坚决要努力,不辜负更多人的指望,常常这一两天挑灯夜战的精心准备,如今将整理出来的iOS10开发的最新知识和心得体会再次分享给你们,让咱们小码哥每个学员都能时刻站在IT界最新的前沿上,学习到最新最潮的技术!spring

   网盘地址: http://pan.baidu.com/s/1i45UWN7 密码:cvr5xcode

   苹果在本地的WWDC结束以后呢,像开发者推送了iOS10系统,虽然是beta版,可是热爱技术人老是不会中止脚步去研究去学习,此次更新主要表如今如下这几个方面。多线程

  1.语音识别 并发

     苹果官方在文档中新增了API   Speech,那么在之前咱们处理语音识别很是的繁琐甚至不少时候可能须要借助于第三方框架处理,那么苹果推出了这个后,咱们之后处理起来就很是的方便了,speech具备如下特色:app

   能够实现连续的语音识别框架

   能够对语 音文件或者语音流进行识别async

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

官方文档:性能

  Snip20160618_28.png

 

Snip20160618_29.png

 

  核心代码:学习

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

  #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以后咱们能够轻松个性化定制了。

     核心代码:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

    //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];

效果图:

333.gif

 

 

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

 

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

   核心代码:

  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

/*

      在iOS 10当中,当我们用户将手机的字体大小进行了设置调整以后,那么app中设置相关代码字体也会跟着一块儿变化 ,支持常见一些字体UI控件 好比uilabel uibutton

     **/

    [super viewDidLoad];

     

    //设置字体的改变大小

    self.labels.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];

    //容许改变

     

    /*

       苹果官方明确的告诉你必须和  preferredFontForTextStyle 或者preferredFontForTextStyle:(NSString *)style compatibleWithTraitCollection 进行结合使用

       注意这里不支持模拟器操做

     **/

     

    self.labels.adjustsFontForContentSizeCategory = YES;

4. UIViewPropertyAnimator属性动画器

 

  那么在iOS 10以前,咱们使用UIView 作动画效果或者自定义一些layer 的动画,若是开始了,通常没法进行中止操做更不能暂停操做,并且一些很是复杂的动画处理也比较麻烦,可是在iOS10,苹果退出了一个全新的API  UIViewPropertyAnimator,可供咱们处理动画操做

 

UIViewPropertyAnimator 是 iOS 10 中新增的一个执行 View 动画的类,具备如下特色:

   可中断性

   可擦除

   可反转性

   丰富的动画时间控制功能

 

 官方文档:

   Snip20160618_30.png

Snip20160618_31.png

核心代码:

  

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

#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

    /**

    @property(nullable, nonatomic, readonly) UICubicTimingParameters *cubicTimingParameters;

    @property(nullable, nonatomic, readonly) UISpringTimingParameters *springTimingParameters;

      

     **/

    //设置弹簧效果 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];

}

 

效果图:

   222.gif

 

 

5.UIColor 新增方法

 

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

 

 

 

关键代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

+ (

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 能够进行监视。

 

  苹果官方解释:

     

 

1

2

3

4

5

6

   //说明在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.

 

 

  关键代码:

1

2

3

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

    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 而且向用户说明.

fff.png

 

 

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。

核心代码:

 

1

2

3

4

5

6

7

8

9

10

11

12

    

//

//  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 (nonatomicstrong, nullable) UIRefreshControl *refreshControl __TVOS_PROHIBITED;

@end

15.GCD多线程支持建立私有队列

相关文章
相关标签/搜索