CTRadioAccessTechnologyDidChangeNotification到新的CTRadioAccessTechnologyDidChangeNotification将导致崩溃如下

时间:2015-10-19 06:35:33

标签: ios exc-bad-access

  1. 如果注释掉代码" dispatch_async"它将导致[[CTTelephonyNetworkInfo alloc] init]崩溃为EXC_BAD_ACCESS;
  2. 如果我不判断" if(!networkInfo)"而不是代码" CTTelephonyNetworkInfo * networkInfo = networkInfo = [[CTTelephonyNetworkInfo alloc] init];"会快速记忆!谢谢!

    viewdidload: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAppCellWithNetworkType:) name:CTRadioAccessTechnologyDidChangeNotification object:nil];
    
    - (void)updateAppCellWithNetworkType:(id)sender{
    
    **//dispatch_async(dispatch_get_main_queue(), ^{**
    
    NSString *type = nil;
    Reachability *currentReach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    if (currentReach.isReachableViaWiFi) {
    type =  @"WiFi";
    }else{
    
    static CTTelephonyNetworkInfo *networkInfo = nil;
    
    **if (!networkInfo) {
        networkInfo = [[CTTelephonyNetworkInfo alloc]init];
    }**
    
    type =  [self getTelephonyNetworkTypeWithCTRadioAccessTechnology:networkInfo.currentRadioAccessTechnology];
    }
    }
    
  3. enter image description here

1 个答案:

答案 0 :(得分:0)

建议不要从Notification observer方法创建CTTelephonyNetworkInfo对象。查看“了解您的电台”部分下的objc.io链接中提供的文档。

这可能会有所帮助,我有类似的经验,这样做可以解决这个问题。