开发者

How to check connection is low and can not download data in iPhone?

开发者 https://www.devze.com 2023-03-01 01:50 出处:网络
I have application in which data are downloaded using wifi or 3G mostly... Sometimes wifi goes down and unable to download data from server.

I have application in which data are downloaded using wifi or 3G mostly...

Sometimes wifi goes down and unable to download data from server.

I have function of checking if internet available by

- (BOOL) connectedToNetwork
{
    NSString *requestString =@"";
    NSData *requestData = [NSData dataWithBytes: [requestStr开发者_如何学JAVAing UTF8String] length: [requestString length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://www.google.com"]];
    [request setHTTPMethod: @"POST"];
    [request setTimeoutInterval:10];
    [request setHTTPBody: requestData];
    return [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ]!=nil;
} 

and i got return TRUE sometimes though low connection..

How to solve this issue?

Your suggestions are very helpful to me.

Thanks in advance


for my application I use Reachability class from this Apple example. hope it helps )

http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html


I would also recommend ASIHTTPRequest, which can help a lot with data downloading.


you must look into apple Reachability API's

Blog tutorial :

http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/

http://www.xprogress.com/post-40-iphone-internet-connection-check-wifi-3g-edge-something-like-reachability-h/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号