iOS 获取手机运营商信号强度

Measuring cellular signal strength

 

https://stackoverflow.com/questions/4954389/measuring-cellular-signal-strength

I am developing a non-appstore app for iOS. I want to read the cellular signal strength in my code.

I know Apple doesn't provide any API by which we can achieve this. 

Is there any private API that can be used to achieve this? I have gone through the various threads regarding this issue but could not find any relevant info.

It is completely possible because there is an app in the app-store for detecting the carrier's signal strength.

ios iphone objective-c cocoa-touch

shareimprove this question

edited Feb 9 '15 at 22:30

skrrgwasme

6,912113763

asked Feb 10 '11 at 7:17

bhatti

140126

add a comment

6 Answers

activeoldestvotes

9

 

I briefly looked at the VAFieldTest project located at Github.

There seems to be  getSignalStrength() and register_notification() functions in Classes/VAFieldTestViewController.m that might be interesting to you as they call into CoreTelephony.framework

I am pretty confident that some of the used calls are undocumented in the CoreTelephony framework documentation from Apple and therefore private - any app in the AppStore must have slipped passed inspection. 

shareimprove this answer

answered Feb 10 '11 at 9:38

Niels Castle

7,4852553

  • @Niels Castle How can I convert the signal strength that I got using VAFieldTest application to dBm? – DeeMar 18 '13 at 11:47

  • Follow the link to Github and you'll be able to interact directly with Vlad, the maintainer of VAFieldTest. – Niels Castle Mar 18 '13 at 15:01

  • Is it possible to get other parameters as well : RSCP (signal level), SC (Scrambling Code) and EcNo (Signal To Noise Ratio)? – luksmir May 17 '13 at 6:27

  • The project crashes almost instantly on iOS 9. – Raptor Dec 3 '15 at 10:37

  • Any idea how OpenSignal does their signal strength measurement ? They show the technology and signal strength on their home screen (tested on iOS 10), and the value is very accurate. – user5365075 Aug 19 '17 at 14:26

show 1 more comment

 

14

 

Get signalStreght IOS9: 

UIApplication *app = [UIApplication sharedApplication];  
NSArray *subviews = [[[app valueForKey:@"statusBar"]     valueForKey:@"foregroundView"] subviews];  
NSString *dataNetworkItemView = nil;  
     for (id subview in subviews) {  
   if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]])  
   {  
        dataNetworkItemView = subview;  
        break;  
    }  
 }  
int signalStrength = [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];  
NSLog(@"signal %d", signalStrength);

shareimprove this answer

edited Dec 21 '15 at 6:02

bummi

25.1k85289

answered Dec 21 '15 at 5:44

vualoaithu

864109

add a comment

10

 

It is not very hard. 

  1. Link CoreTelephony.framework in your Xcode project
  2. Add the following lines where you need it

Code:

int CTGetSignalStrength(); // private method (not in the header) of Core Telephony

- (void)aScanMethod
{
    NSLog(@"%d", CTGetSignalStrength()); // or do what you want
}

And you are done.

Update May 2016

Apple removed this opportunity.

shareimprove this answer

edited Apr 29 '16 at 11:15

answered Sep 18 '13 at 8:19

Michael Dorner

6,59094269

add a comment

5

 

To get signal streght in iOS 9 or above in Swift 3, without using the private API from CoreTelephony - CTGetSignalStrength(). Just scouring the statusBar view.

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

}

Attention: If the status bar is hidden, the key "statusBar" will return nil.

shareimprove this answer

edited Jun 14 '17 at 1:01

answered Dec 15 '16 at 17:52

Lucas Freitas de Oliveira

5114

show 3 more comments

1

 

I haven't tested it, but apparently this is now a method of CTTelephonyNetworkInfo instead of a global/static function.

The return type is id, so I think you get either a NSDictionary (as the _cachedSignalStrengthivar implies) or an NSNumber (as the old function implies).

id signalStrength = [[CTTelephonyNetworkInfo new] signalStrength];

This changed in iOS 8.3, as you can see from the commit.

Note that this is still not documented! So if your app will go in the App Store, take your precautions.

shareimprove this answer

edited Dec 3 '15 at 10:48

Raptor

34.7k31175287

answered Jul 3 '15 at 15:50

Alessandro Vendruscolo

9,73232638

  • 2

    signalStrength returns null in iOS 9 – Raptor Dec 3 '15 at 10:59

  • I am trying to get the cellular signal strength for iOS 9 but as mentioned above its returning 0. Using UIStatusBarSignalStrengthItemView does not work in background mode so it is of no use as i need to get signal strength in background. Please let me know if anybody is able to get the values. – iOS Dev Sep 20 '16 at 12:33

add a comment

0

 

Here's Lucas' answer converted to Xamarin, and tested on iOS 10.2.1:

var application = UIApplication.SharedApplication;
var statusBarView = application.ValueForKey(new NSString("statusBar")) as UIView;
var foregroundView = statusBarView.ValueForKey(new NSString("foregroundView")) as UIView;

UIView dataNetworkItemView = null;
foreach (UIView subview in foregroundView.Subviews)
{
    if ("UIStatusBarSignalStrengthItemView" == subview.Class.Name)
    {
        dataNetworkItemView = subview;
        break;
    }
}
if (null == dataNetworkItemView)
    return false; //NO SERVICE

int bars = ((NSNumber)dataNetworkItemView.ValueForKey(new NSString("signalStrengthBars"))).Int32Value;

shareimprove this answer

answered Feb 1 '17 at 3:23

Eliot Gillum

417413

add a comment

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值