问题
I was fetching Cellular Signal Strength(iOS < 11) as mentioned below, but in iOS 11 , signalStrength is always 0
let statusBarView = UIApplication.shared.value(forKey: "statusBar") as? UIView
if let foregroundView = statusBarView?.value(forKey: "foregroundView") as? UIView {
let subiews = foregroundView.subviews
var dataNetworkItemView:UIView?
for subview in subiews {
if subview.isKind(of: NSClassFromString("UIStatusBarSignalStrengthItemView")!) == true {
dataNetworkItemView = subview
break
}
}
var signalStrength = 0
var signalStrengthBars = 0
if let view = dataNetworkItemView {
signalStrength = view.value(forKey: "signalStrengthRaw") as! Int
signalStrengthBars = view.value(forKey: "signalStrengthBars") as! Int
}
来源:https://stackoverflow.com/questions/46462712/ios-11-cellular-signal-strength