* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIStatusBar_Modern 0x106207ee0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.'
* First throw call stack:
(0x182907d38 0x181b5c528 0x182907a00 0x1832af864 0x1831f5f70 0x1043d2af4 0x1043d1354 0x1043bf0e0 0x1043bf01c 0x105b9545c 0x105b9617c 0x1043befb4 0x10439fe34 0x105b9549c 0x105b9545c 0x105b9a050 0x1828aff20 0x1828adafc 0x1827ce2d8 0x184660f84 0x18bd8d034 0x102e46d18 0x1822f256c)
libc++abi.dylib: terminating with uncaught exception of type NSException

只出现在 iphone X

2017-11-28 提问

查看全部 5 个回答


这个问题之前没遇到过, 不过Stack Overflow上已经有人回答了.

NSArray *subviews = nil;
id statusBar = [[UIApplication sharedApplication] valueForKey:@"statusBar"];
if ([statusBar isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
    subviews = [[[statusBar valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
} else {
    subviews = [[statusBar valueForKey:@"foregroundView"] subviews];

<UIStatusBar>this class is not key value coding-compliant for the key foregroundView.