我在 viewDidLoad 中有如下示例代码来检测热点开/关。它在 iPhone 6-8 中正常工作,但在 iPhone X 中崩溃。
UIApplication *app = [UIApplication sharedApplication];
if(![[app valueForKey:@"statusBar"] valueForKey:@"doubleHeightLabel"])
{
//Some code here
}
else
{
//Some code here
}
显示错误信息:-
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIStatusBar_Modern 0x7ffed341b7f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key doubleHeightLabel.'
有什么想法吗?
最佳答案
有一种方法可以检查CNCopyCurrentNetowrkInfo获取当前网络信息。
还有技巧:
objective-c :
CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
swift :
let statusBarHeight = UIApplication.shared.statusBarFrame.size.height
启用个人热点时,它返回 40,否则返回 20。
请注意它不适用于 iPhone X+
关于ios - 检测热点在 iPhone X 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52377726/