OGeek|极客世界-中国程序员成长平台

标题: iphone - 如何找到准确的移动信号强度和服务提供商名称? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:23
标题: iphone - 如何找到准确的移动信号强度和服务提供商名称?

在我的应用程序中,我想获取移动网络信号强度和网络提供商名称, 在下面的代码中,它返回了信号强度,但我感觉它并不准确,因为当强度值达到 60% 时,信号棒也显示满了。并且网络提供商名称作为运营商返回。我是每 2 秒调用一次此方法。

-(void)UpdateLabelWithSignal{
   int str = CTGetSignalStrength();
   NSLog(@"SignalStrength:%d",str);
   NSLog(@"SignalStrength:%@",[NSString stringWithFormat"%d",str]);
   SignalLabel.text = [NSString stringWithFormat"%d",str];

}

//获取网络提供商名称的代码

    CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [netinfo subscriberCellularProvider];
    NSLog(@"MY NAME:%@",carrier.carrierName);   



Best Answer-推荐答案


如果您希望它每隔几秒准确更新一次。这里是代码。

 - (void)viewDidLoad
 {
  [super viewDidLoad];

  printf("signal strength: %d\n", CTGetSignalStrength());
 slimeDeathAnimTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selectorselector(UpdateLabelWithSignal) userInfo:nil repeats:YES];
  CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
  CTCarrier *carrier = [netinfo subscriberCellularProvider];
  NSLog(@"MY NAME:%@",carrier.carrierName);

  NSLog(@"mobileCountryCode = %@",carrier.mobileCountryCode);
  NSLog(@"mobileNetworkCode = %@",carrier.mobileNetworkCode);
  NSLog(@"isoCountryCode = %@",carrier.isoCountryCode);
  NSLog(@"allowVOIP = %d",carrier.allowsVOIP);

  }

-(void)UpdateLabelWithSignal{

int str = CTGetSignalStrength();
NSLog(@"SignalStrength:%d",str);
  NSLog(@"SignalStrength:%@",[NSString stringWithFormat"%d",str]);
SignalLabel.text = [NSString stringWithFormat"%d",str];

}

关于iphone - 如何找到准确的移动信号强度和服务提供商名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16785734/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4