iphone - 可达性 block 应用

标签 iphone ios xcode connection-string reachability

在我的应用程序中的 appDelegate.m 中,我插入了可达性代码,就像苹果说的那样:

-(BOOL)checkInternet
{
Reachability *r = [Reachability reachabilityWithHostName:@"google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
BOOL internet;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
    internet = NO;
} else {
    internet = YES;
}
return internet;
}

在我的 viewcontroller.m 方法中 - (void)applicationDidBecomeActive:(UIApplication *)application {

gotInternet = [self checkInternet];
if ( gotInternet == 0)
{
//No connection
} else {
//Connection ok
} 

但是当 3g 网络出现问题时,我的应用程序在大约 20 秒后就会因为延迟过多而崩溃。如何异步实现控制连接,而不带看门狗?

谢谢

最佳答案

看看 NSOperationconcurrency programming guide .

关于iphone - 可达性 block 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8238549/

相关文章:

ios - 在自定义 UITableViewCell 中,在哪里将 Observer 添加到 NSNotificationcenter?

xcode - Swift - 表达式类型在没有更多上下文的情况下不明确

iphone - NSPersistentStoreCoordinator 线程安全吗?

iphone - 倒计时应用程序给出预期的 "]"错误

iphone - 如何减少iPhone中多行UILabel中两行之间的间距

ios - 我从头开始的团队配置是什么?

iOS 应用程序在 AppStore 中更新时会崩溃,但在 Xcode 中安装时不会崩溃

objective-c - paymentWithProductIdentifier 在应用程序购买特定中已弃用

iphone - 如何在注释周围添加一个圆作为半径

ios - Swift - 委托(delegate) - 如何将协议(protocol)链接到已实现的委托(delegate)方法?