前言
本文主要给大家介绍了关于iOS12适配及问题的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
版本信息
Xcode: Version 10.0 beta (10L176w)
macOS: 10.14 Beta (18A293u)
iOS: 12.0(16A5288q)
问题及解决过程
1,StatusBar内部结构改变
现象:crash
crash log:
1,-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820
2,Terminating app due to uncaught exception ‘NSInvalidArgumentException', reason: ‘-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820'
———————————————————————————————
问题代码和解决方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
+ (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;
}
|
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对服务器之家的支持。
原文链接:https://blog.csdn.net/wxs0124/article/details/80613847