【问题标题】:How to find accurate mobile signal strength and Service Provider Name?如何找到准确的移动信号强度和服务提供商名称?
【发布时间】:2013-05-28 18:03:37
【问题描述】:

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

【问题讨论】:

  • 我不明白
  • 这可能是 thisthis 的重复项,请查看 this 链接以获取您的解决方案
  • 你能把代码发给我吗?
  • int CTGetSignalStrength(); - (void)viewDidLoad { [超级 viewDidLoad]; // 在加载视图后做任何额外的设置,通常是从一个 nib。 while (true) { NSLog(@"信号强度:%d\n", CTGetSignalStrength());睡眠(1); } }

标签: iphone ios core-telephony


【解决方案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];

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    • 2023-04-10
    • 2016-01-08
    相关资源
    最近更新 更多