Reputation: 110
While looking for a simple asynchronous method to check for internet access in iOS, I had an idea, using a UIWebView to handle asynchronicity:
-(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
}
This seems to be working, but I wanted to know if there are any hidden dangers I might not be aware of in this approach. Any ideas?
Upvotes: 2
Views: 88
Reputation: 35783
There are two drawbacks to this approach, but there's not much to be done:
Upvotes: 2