iOS12适配指南

1.重复文件报错

build Phases-> 删除多余的info.plist

2.library not found for -lstdc++

苹果在XCode10和iOS12中移除了libstdc++这个库,由libc++这个库取而代之,苹果的解释是lib转载自斗玩网stdc++已经标记为废弃有5年了,建议大家使用经过了llvm优化过并且全面支持C++11的libc++库。

建议把代码调整为依赖 libc++库 如果你引用的第三方厂商提供的sdk中依赖了libstdc++,联系厂商

3.StatusBar内部结构改变

现象:crash
  
  crash log:
  
  -[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820
  
  * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820’        

解决方案:

+ (NSString *)getIphoneXNetWorkStates {    
    UIApplication *app = [UIApplication sharedApplication];
    id statusBar = [[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"statusBar"];
    id one = [statusBar valueForKeyPath:@"regions"];
    id two = [one valueForKeyPath:@"trailing"];
    NSArray *three = [two valueForKeyPath:@"displayItems"];
    NSString *state = @"无网络";
    for (UIView *view in three) {
        //alert: iOS12.0 情况下identifier的变成了类"_UIStatusBarIdentifier"而不是NSString,所以会在调用“isEqualToString”方法时发生crash,
        //修改前
//        NSString *identifier = [view valueForKeyPath:@"identifier"];
        //修改后
        NSString *identifier = [[view valueForKeyPath:@"identifier"] description];
        if ([identifier isEqualToString:@"_UIStatusBarWifiItem.signalStrengthDisplayIdentifier"]) {
            id item = [view valueForKeyPath:@"_item"];

            //alert: 这个问题和上边一样itemId是_UIStatusBarIdentifier 类型,不是string
            NSString *itemId = [[item valueForKeyPath:@"identifier"] description];
            if ([itemId isEqualToString:@"_UIStatusBarWifiItem"]) {
                state = @"WIFI";
            }
            state = @"不确定";

        } else if ([identifier isEqualToString:@"_UIStatusBarCellularItem.typeDisplayIdentifier"]) {
            UIView *statusBarStringView = [view valueForKeyPath:@"_view"];
            // 4G/3G/E
            state = [statusBarStringView valueForKeyPath:@"text"];
        }

    }

    return state;
}   

4.新版本iPhoneXR,iPhoneXS,iPhoneXS MAX适配

iOS12适配指南

  • 各个机型枚举
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
 
#define iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
 
#define iPhoneXS_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)
  • 目前iPhonex都是刘海屏,判断处这个特性,就可以统一做适配了

    #define isIPhoneXAll ([UIScreen mainScreen].bounds.size.height == 812 || [UIScreen mainScreen].bounds.size.height == 896)
  • 目前iPhonex都是刘海屏,状态栏的高度均为44pt

    #define isIPhoneXAl ([[UIApplication sharedApplication] statusBarFrame].size.height == 44)
  • 针对继承自UIScrollView的,需要处理一下内边距 第一步:关闭自动调整内边距

    if (@available(iOS 11.0, *)) {
            [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

iOS12适配指南

上一篇:iOS 控制台打印unicode 转中文汉字 UTF8String


下一篇:IOS内购(IAP)的那些事