在寻找一种简单的异步方法来检查iOS中的internet访问时,我有一个想法,使用UIWebView来处理异步性:
-(void) testNet
{
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
webview.delegate=self;
NSString *urlAddress = @"http://bla.com/dummySmallFile.txt";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webview loadRequest:requestObj];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
//deal with no net stuff here
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//net is there, use it here
}这似乎是可行的,但我想知道在这种方法中是否存在任何我可能没有意识到的潜在危险。有什么想法吗?
发布于 2013-09-30 21:51:34
这种方法有两个缺点,但没有什么可做的:
https://stackoverflow.com/questions/19104451
复制相似问题