有问题计算Wi-Fi强度
我想获得设备Wi-Fi强度,但是
现在没有找到直接的方法来实现此操作,我已经有了它曾经在iOS 13之前工作的,但是现在我崩溃了。
func wifiStrength() -> Double {
let app = UIApplication.shared
let subviews = ((app.value(forKey: "statusBar") as! NSObject).value(forKey: "foregroundView") as! UIView).subviews
var dataNetworkItemView: UIView?
for subview in subviews {
if subview.isKind(of: NSClassFromString("UIStatusBarDataNetworkItemView")!) {
dataNetworkItemView = subview
break
}
}
let dBm = (dataNetworkItemView!.value(forKey: "wifiStrengthRaw") as! NSNumber).intValue
var strength = (Double(dBm) + 90.0) / 60.0
if strength > 1 {
strength = 1
}
return strength
}
崩溃错误消息。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
终止以未被发现的方式终止NSexception类型,
有人知道如何适应iOS 13上的先前方法吗? 或一种不同的方式来收集Wi-Fi信号强度。
I want to get the device Wi-Fi strength, but found no straightforward way to accomplish this
Right now I have this which used to work before iOS 13 however now I get this crash.
func wifiStrength() -> Double {
let app = UIApplication.shared
let subviews = ((app.value(forKey: "statusBar") as! NSObject).value(forKey: "foregroundView") as! UIView).subviews
var dataNetworkItemView: UIView?
for subview in subviews {
if subview.isKind(of: NSClassFromString("UIStatusBarDataNetworkItemView")!) {
dataNetworkItemView = subview
break
}
}
let dBm = (dataNetworkItemView!.value(forKey: "wifiStrengthRaw") as! NSNumber).intValue
var strength = (Double(dBm) + 90.0) / 60.0
if strength > 1 {
strength = 1
}
return strength
}
The crash error message.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
terminating with uncaught exception of type NSException
Does anyone know how to adapt the previous approach on iOS 13?
Or of a different way to gather Wi-Fi signal strength.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法在iOS应用程序上获得WiFi强度。请在Apple开发人员论坛中查看此线程:
使用
value(forkey:)< / code>不支持,不稳定,并且可以将您的应用程序从应用程序中拒绝店铺。
There is no way to get wifi strength on an iOS application. Please see this thread in Apple Developer Forums: https://developer.apple.com/forums/thread/107046?answerId=325726022#325726022
Rooting around internal / private structures using
value(forKey:)
is unsupported, unstable, and could get your app rejected from the app store.我解决了问题,这是
I solve the problem this is the updated code which works on iOS 15
In regards to AppStore legality, I am aware that this practice is not allowed by apple, and want to clarify that I'm not planning to use this in any production code just for pure experimentation sake.