2015-10-19 109 views
1
  1. 如果註釋掉的代碼「dispatch_async」這將導致在碰撞[CTTelephonyNetworkInfo的alloc]初始化]爲EXC_BAD_ACCESS;
  2. 如果我不判斷「if(!networkInfo)」而不是代碼「CTTelephonyNetworkInfo * networkInfo = networkInfo = [[CTTelephonyNetworkInfo alloc] init];」將導致記憶快速!謝謝!CTRadioAccessTechnologyDidChangeNotification新CTRadioAccessTechnologyDidChangeNotification會導致崩潰如下

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

enter image description here

回答

0

據表示,不創建從通知觀察者方法CTTelephonyNetworkInfo對象。檢查「Know Your Ra​​dio」部分下的objc.io鏈接中提供的文檔。

這可能有幫助,我有類似的經歷,並且這樣做可以修復崩潰。