目前很多游戲在iPhone X手機 wifi情況下,啟動時候閃退,在4G網絡時候不閃退。
閃退的log:
#0 Thread NSUnknownKeyException [<UIStatusBar_Modern 0x15f906160> valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.
這是項目中使用狀態欄中圖標判斷當前網絡的具體狀態,而 iPhone X手機狀態欄和其他版本手機存在差異,狀態欄是多嵌套了一層,所以在讀取時候需要注意。
可以在代碼里面搜索 foregroundView 這個關鍵字,找到位置進行必要修改。
NSArray *children; // 不能用 [[self deviceVersion] isEqualToString:@"iPhone X"] 來判斷,因為模擬器不會返回 iPhone X if ([[application valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) { children = [[[[application valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews]; } else { children = [[[application valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews]; }