如何在iPhone中检查连接低且无法下载数据?
如何在iPhone中检查连接低且无法下载数据?,iphone,connection,wifi,Iphone,Connection,Wifi,我有一个应用程序,其中数据主要通过wifi或3G下载… 有时wifi关闭,无法从服务器下载数据。 我的功能是检查网络是否可用 - (BOOL) connectedToNetwork { NSString *requestString =@""; NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]]; NSMutableU
我有一个应用程序,其中数据主要通过wifi或3G下载…
有时wifi关闭,无法从服务器下载数据。
我的功能是检查网络是否可用
- (BOOL) connectedToNetwork
{
NSString *requestString =@"";
NSData *requestData = [NSData dataWithBytes: [requestString 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;
}
有时,通过低连接,我得到的返回值为真。如何解决这个问题?
你的建议对我很有帮助。
提前感谢对于我的应用程序,我使用了这个苹果示例中的可达性类。(希望有帮助)
我也推荐,这对数据下载有很大帮助。您必须了解apple的可达性API 博客教程: