美文网首页iOS开发笔记
iPhoneX使用状态栏中图标判断当前网络的具体状态

iPhoneX使用状态栏中图标判断当前网络的具体状态

作者: jamy1003 | 来源:发表于2017-11-07 14:55 被阅读641次

在使用xcode9运行iPhoneX模拟器时偶然发现报错

reason: '[<UIStatusBar_Modern 0x7f8e73303830> valueForUndefinedKey:]: this class is not key value coding-compliant for the key foregroundView.'

原来由于iPhone X的状态栏多嵌套了一层,和其他版本手机差异比较大的,因此在获取状态栏网络状态时也需要多取一次。

UIApplication *application = [UIApplication sharedApplication];
NSArray *children;
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];
}

相关文章

网友评论

    本文标题:iPhoneX使用状态栏中图标判断当前网络的具体状态

    本文链接:https://www.haomeiwen.com/subject/zqljmxtx.html