如果我不判断" 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];
}
}
答案 0 :(得分:0)
建议不要从Notification observer方法创建CTTelephonyNetworkInfo对象。查看“了解您的电台”部分下的objc.io链接中提供的文档。
这可能会有所帮助,我有类似的经验,这样做可以解决这个问题。