iOS 10 的一些资料整理

 

文/判若两人丶(简书作者)
原文链接:http://www.jianshu.com/p/0cc7aad638d9

1.iOS 10 隐私权限设置

iOS 10 开始对隐私权限更加严格,如果你不设置就会直接崩溃,现在很多遇到崩溃问题了,一般解决办法都是在info.plist文件添加对应的Key-Value就可以了。

以上Value值,圈出的红线部分的文字是展示给用户看的,需要自己添加规范的提示说明,不能为空。目前解决办法基本都一样,参考学习文章如下:
兼容iOS 10:配置获取隐私数据权限声明

2.Xcode 8 运行一堆没用的logs解决办法

上图我们看到,自己新建的一个工程啥也没干就打印一堆烂七八糟的东西,我觉得这个应该是Xcode 8的问题,具体也没细研究,解决办法是设置OS_ACTIVITY_MODE : disable如下图:

3.iOS 10 UIStatusBar方法过期:

在我们开发中有可能用到UIStatusBar一些属性,在iOS 10 中这些方法已经过期了,如果你的项目中有用的话就得需要适配。上面的图片也能发现,如果在iOS 10中你需要使用preferredStatusBar比如这样:

//iOS 10 
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

4.iOS 10 UIColor 新增方法

因为之前我们都是用RGB来设置颜色,反正用起来也不是特别多样化,这次新增的方法应该就是一个弥补吧。所以在iOS 10 苹果官方建议我们使用sRGB,因为它性能更好,色彩更丰富。如果你自己为UIColor写了一套分类的话也可尝试替换为sRGBUIColor类中新增了两个Api如下:

+ (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);

- (UIColor *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);

5.iOS 10 UITextContentType

// The textContentType property is to provide the keyboard with extra information about the semantic intent of the text document.

@property(nonatomic,copy) UITextContentType textContentType NS_AVAILABLE_IOS(10_0); // default is nil

在iOS 10 UITextField添加了textContentType枚举,指示文本输入区域所期望的语义意义。

使用此属性可以给键盘和系统信息,关于用户输入的内容的预期的语义意义。例如,您可以指定一个文本字段,用户填写收到一封电子邮件确认uitextcontenttypeemailaddress。当您提供有关您期望用户在文本输入区域中输入的内容的信息时,系统可以在某些情况下自动选择适当的键盘,并提高键盘修正和主动与其他文本输入机会的整合。

6.iOS 10 字体随着手机系统字体而改变

当我们手机系统字体改变了之后,那我们Applabel也会跟着一起变化,这需要我们写很多代码来进一步处理才能实现,但是iOS 10 提供了这样的属性adjustsFontForContentSizeCategory来设置。因为没有真机,具体实际操作还没去实现,如果理解错误帮忙指正

 UILabel *myLabel = [UILabel new];

   /*
    UIFont 的preferredFontForTextStyle: 意思是指定一个样式,并让字体大小符合用户设定的字体大小。
   */
    myLabel.font =[UIFont preferredFontForTextStyle: UIFontTextStyleHeadline];

 /*
 Indicates whether the corresponding element should automatically update its font when the device’s UIContentSizeCategory is changed.
 For this property to take effect, the element’s font must be a font vended using +preferredFontForTextStyle: or +preferredFontForTextStyle:compatibleWithTraitCollection: with a valid UIFontTextStyle.
 */
     //是否更新字体的变化
    myLabel.adjustsFontForContentSizeCategory = YES;

7.iOS 10 判断系统版本正确姿势

//值为 1
[[[[UIDevice currentDevice] systemVersion] substringToIndex:1] integerValue]
//值为10.000000
[[UIDevice currentDevice] systemVersion].floatValue,
//值为10.0
[[UIDevice currentDevice] systemVersion]

所以说判断系统方法最好还是用后面的两种方法,哦~我忘记说了[[UIDevice currentDevice] systemVersion].floatValue这个方法也是不靠谱的,好像在8.3版本输出的值是8.2,记不清楚了反正是不靠谱的,所以建议大家用[[UIDevice currentDevice] systemVersion]这个方法!
swift 判断如下

 if #available(iOS 10.0, *) {
            // iOS 10.0
            print("iOS 10.0");
        } else { }

8.Xcode 8使用Xib awakeFromNib的警告问题

Xcode 8之前我们使用Xib初始化- (void)awakeFromNib {}都是这么写也没什么问题,但是在Xcode 8会有如下警告:

 

如果不喜欢这个警告的话,应该明确的加上[super awakeFromNib];

9.iOS 10 ImagePickerController.cameraViewTransform问题

很多人反映自定义相机出现了问题,cameraViewTransform不能用了,其实网上关于这个的资料不是很多,在这里提供参考办法如下:

  • 通过监听AVCaptureSessionDidStartRunningNotification来解决
     //#import <AVFoundation/AVFoundation.h>
      //监听
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cameraNotification:) name:AVCaptureSessionDidStartRunningNotification object:nil];
      //监听方法
      - (void)cameraNotification:(NSNotification *)notification {
        dispatch_async(dispatch_get_main_queue(), ^{
              // 这里实现
              imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(50,  50);
          });
      }

    使用AVFoundation框架
    看来UIImagePickerController视乎不在适用于iOS 10了。所以说可以选择AVFoundation来解决这个问题。

posted @ 2016-10-07 16:13  _水畔竹汐  阅读(460)  评论(0编辑  收藏  举报