2

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

1 回答 1

1

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

 - (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];

}
于 2013-05-28T10:03:37.737 回答