在我的应用程序中,我想获取移动网络信号强度和网络提供商的名称,
在下面的代码中,它正在返回信号强度,但我不觉得它很准确,因为当强度值达到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);

最佳答案

如果您希望它每隔几秒钟准确更新一次,则代码如下。

 - (void)viewDidLoad
 {
  [super viewDidLoad];

  printf("signal strength: %d\n", CTGetSignalStrength());
 slimeDeathAnimTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(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/

10-11 17:24