zoukankan      html  css  js  c++  java
  • iOS10和Xcode8适配

    1 Xib文件的注意事项

    使用Xcode8打开xib文件后,会出现下图的提示。

    ios10-adaptation-1

    大家选择Choose Device即可。 
    之后大家会发现布局啊,frame乱了,只需要更新一下frame即可。如下图

    ios10-adaptation-2
    注意:如果按上面的步骤操作后,在用Xcode7打开Xib会报一下错误,

    ios10-adaptation-3 
    解决办法:需要删除Xib里面

    <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    

    这句话,以及把< document >中的toolsVersion和< plugIn >中的version改成你正常的xib文件中的值.

    2 推送

    如下图的部分,不要忘记打开。所有的推送平台,不管是极光还是什么的,要想收到推送,这个是必须打开的。

    ios10-adaptation-4

    推送的代理<UNUserNotificationCenterDelegate>iOS10收到通知不再是在[application: didReceiveRemoteNotification:]方法去处理, iOS10推出新的代理方法,接收和处理各类通知(本地或者远程)

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { 
    //应用在前台收到通知 NSLog(@"========%@", notification);
    }
    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { 
    //点击通知进入应用 NSLog(@"response:%@", response);
    }

    3 屏蔽Xcode 8杂乱无章的log

    更新Xcode8之后,新建立工程,都会打印一堆莫名其妙看不懂的Log. 
    如这些

    subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1,

    屏蔽的方法如下: 
    Xcode8里边 Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加

    OS_ACTIVITY_MODE = Disable

    ios10-adaptation-5
    如果写了之后还是打印log,请重新勾选对勾,就可以解决了

    考虑到添加上述内容在Xcode8后,真机调试可能出现异常,大家可以自定义一个宏定义,来做日志输出。

    #ifdef DEBUG
    
    #define DDLOG(...) printf(" %s
    ",[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
    #define DDLOG_CURRENT_METHOD NSLog(@"%@-%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))
    
    #else
    
    #define DDLOG(...) ;
    #define DDLOG_CURRENT_METHOD ;
    
    #endif

    4 权限以及相关设置

    iOS10调用相册会Crash下面信息

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

    大体意思就是这个App缺少一个获取私有(敏感)数据的权限描述,需要我们在info.plist文件中必须含有一个名字叫做NSPhotoLibraryUsageDescription的值来解释为什么应用需要使用这个数据,没错,获取相册资源的键值就是NSPhotoLibraryUsageDescription 

    去plist文件中添加了下面的键值: 

    ios10-adaptation-6

    这个时候再点击获取图片资源,就弹出了一个获取权限的问候,不会发生崩溃了:

    ios10-adaptation-7

    除了相册的权限,iOS10之后如下的权限请求也是需要我们填写请求描述的

    ios10-adaptation-8

    Privacy - Microphone Usage Description //麦克风权限
    Privacy - Contacts Usage Description   //通讯录权限
    Privacy - Camera Usage Description     //摄像头权限
    Privacy - NSSiriUsageDescription       //Siri的权限
    Privacy - Bluetooth Peripheral Usage Description //蓝牙
    Privacy - Reminders Usage Description  //提醒事项
    Privacy - Motion Usage Description     //运动与健康
    Privacy - Media Libaray Usage Description //媒体资源库
    Privacy - Calendars Usage Description  //日历
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    5 iOS 10开始项目中有的文字显示不全问题

    我用Xcode 8 和Xcode 7.3分别测试了下,如下图:

    ios10-adaptation-9

    ios10-adaptation-10

    创建一个Label然后让它自适应大小,字体大小都是17最后输出的宽度是不一样的,我们再看一下,下面的数据就知道为什么升级iOS 10 之后App中有的文字显示不全了:

    Xcode 8打印Xcode 7.3打印
    1个文字宽度:17.5 1个文字宽度:17
    2个文字宽度:35 2个文字宽度:34
    3个文字宽度:52 3个文字宽度:51
    4个文字宽度:69.5 4个文字宽度:68
    5个文字宽度:87 5个文字宽度:85
    6个文字宽度:104 6个文字宽度:102
    7个文字宽度:121.5 7个文字宽度:119
    8个文字宽度:139 8个文字宽度:136
    9个文字宽度:156 9个文字宽度:153
    10个文字宽度:173.5 10个文字宽度:170

    英文字母会不会也有这种问题,我又通过测试,后来发现英文字母没有问题,只有汉字有问题。 
    目前可行的解决方法:

    //@property(nonatomic) BOOL adjustsFontSizeToFitWidth; // default is NO
    
    
    label.adjustsFontSizeToFitWidth = YES;//设置成YES就可以啦
    

    6 xib设定好固定尺寸在代码中获取控件尺寸都变成(0,0,1000,1000)

    UIView中要从- (void)updateConstraints或者- (void)drawRect:(CGRect)rect获取控件尺寸。

    - (void)updateConstraints
    {
        [super updateConstraints];
    }
    
    - (void)drawRect:(CGRect)rect
    {
        [super drawRect:rect];
    }

    UIViewController中要从- (void)viewDidLayoutSubviews获取控件尺寸。

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
    }

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

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

    ios10-adaptation-11

    如果不喜欢这个警告的话,应该明确的加上[super awakeFromNib];我们来看看官方说明:

    You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

    参考

    http://www.jianshu.com/p/484a909b4772

  • 相关阅读:
    出差归来
    五一假期的开端
    哭。。。五一这就过拉。。。还没什么感觉那。。。呜呜
    爱姬家族新成员。。。
    大道至简读后感
    假期进度报告
    假期报告
    假期进度报告
    假期进度报告
    假期进度报告
  • 原文地址:https://www.cnblogs.com/isItOk/p/5966379.html
Copyright © 2011-2022 走看看