1
- 如果註釋掉的代碼「dispatch_async」這將導致在碰撞[CTTelephonyNetworkInfo的alloc]初始化]爲EXC_BAD_ACCESS;
如果我不判斷「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]; } }