如何获取iPhone网络的信号强度(RSRP / RSSI / RSRQ / SINR),小区ID(LTE / 3G / 2G)

时间:2019-01-04 12:42:55

标签: ios iphone swift

  

我正在使用该代码获取信号强度,但每次都会返回0。请建议我如何找到信号强度。

func getSignalStrength() -> Int {

    let application = UIApplication.shared
    let statusBarView = application.value(forKey: "statusBar") as! UIView
    let foregroundView = statusBarView.value(forKey: "foregroundView") as! UIView
    let foregroundViewSubviews = foregroundView.subviews

    var dataNetworkItemView:UIView!

    for subview in foregroundViewSubviews {
        if subview.isKind(of: NSClassFromString("UIStatusBarSignalStrengthItemView")!) {
            dataNetworkItemView = subview
            break
        } else {
            return 0 //NO SERVICE
        }
    }

    return dataNetworkItemView.value(forKey: "signalStrengthBars") as! Int

}

1 个答案:

答案 0 :(得分:0)

没有官方支持的方法来获取蜂窝信号强度。也许某些Private Api可以做到这一点,但其非法和应用程序将被拒绝