每次网络状态从无网络变为网络时,我的应用程序崩溃,反之亦然,在以下行使用EXC_BAD_ACCESS:
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification
object:self];
});
我使用以下方式通过app delegate进行调用:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
[self checkNetworkStatus:nil];
和
-(void) checkNetworkStatus:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReach currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"The internet is down.");
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
break;
}
}
}
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
这可能会对您有所帮助:Reachability Classes crashing program - not sure why
我遇到了将Reachability对象在不同线程上释放到创建它们的问题。我看到你在主队列上分配Reachability,你也在那里解除分配吗?