iOS 11 : Cellular Signal strength

2020-07-27 05:10发布

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
                }

0条回答
登录 后发表回答