iOS适配整理

iOS12适配问题

1.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;
}

2.libstdc++ 库 和 libc++

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

解决方案:,如果你自己的业务模块使用了libstdc++,那么就把模块代码重新调整为依赖libc++,然后重新检查是否存在问题,重新编译,如果项目需要C++,则再添加libc++.tbd

2、报错如下:

error: Embedded binary is not signed with the same certificate as the parent app. Verify the embedded binary target's code sign settings match the parent app's.

                   Embedded Binary Signing Certificate: Software Signing

                  Parent App Signing Certificate: - (Ad Hoc Code Signed)

3、报错如下:

error: Multiple commands produce 'xxxx':

1) Target 'xxxModule' (project 'Pods') has copy command from 'xxxx' to 'yyyy'

2) Target 'xxxModule' (project 'Pods') has copy command from 'zzzz' to 'pppp'

这里2、3都是xcode对工程配置强校验引起的,很棘手,找了很久才基本解决掉,解决方法是一致的,在 Xcode--->File下进行工程设置,如下图(project setting或workspace setting):

这里相当于是将xcode build的设置修改为原来的配置了。如何在新的build 系统下解决这些问题,还待进一步研究。

iPhoneXR,iPhoneXS,iPhoneXS MAX适配

1.各种机型的判断方法:

  • 各个机型枚举
#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;
}

原文地址:https://www.cnblogs.com/niit-soft-518/p/9698196.html