iOS13适配汇总

1、deviceToken的数据结构改变,需要更改取值方法(参考友盟):

if (![deviceToken isKindOfClass:[NSData class]]) return;
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                      ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                      ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                      ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
self.devToken = hexToken;
NSLog(@"deviceToken:%@", self.devToken);

2、设置状态栏的背景颜色,原有的方式用到了KVC的valueForKey:方法来获取系统API的私有属性,程序会crash,我的做法是这样的:

/**设置状态栏背景颜色*/
+ (void)setStatusBarBackgroundColor:(UIColor *)color control:(UIViewController *)control
{
    // iOS13 之前
    /*
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
     */
    
    // iOS13 之后
    control.navigationController.navigationBar.barTintColor = color;
}

3、新增设备型号:苹果官网设备型号说明,如果项目中用到了这个,需要把新增的设备型号加进去!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容