在我的应用程序中,我想获得移动网络信号强度和网络提供商名称, 在下面的代码中,它返回信号强度,但我感觉不准确,因为当强度值达到60%时,信号棒也显示为满。并且网络提供商名称作为carrier.i'm返回每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);
答案 0 :(得分: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];
}