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.[UIImage imageNamed:]不能正常加載Assets中的圖片

解決: 
將圖片放到bundle中 
使用一下方式加載即可

NSString *path = [[NSBundle mainBundle] pathForResource:@"bg_login" ofType:@"png"]; _backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:path]];

這個不能正常加載的情況只出現在個別的地方,目前找到的共性是加載的圖片偏大.

 

其他bug 參考

https://juejin.im/post/5b1634f0f265da6e61788998

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM