可达性块应用

Posted

技术标签:

【中文标题】可达性块应用【英文标题】:Reachability block application 【发布时间】:2011-11-23 07:24:48 【问题描述】:

在我的 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 秒后由于延迟过多而崩溃。如何异步实现控制连接,不带看门狗?

谢谢

【问题讨论】:

【参考方案1】:

看看NSOperation 和concurrency programming guide。

【讨论】:

以上是关于可达性块应用的主要内容,如果未能解决你的问题,请参考以下文章