1
我試過檢查是否有連接到google.com 但是這種方法無法正常工作? 你能告訴我我的錯嗎? 此致拉斐爾檢查互聯網連接
- (BOOL)networkConnected {
SCNetworkReachabilityFlags flags = 0;
SCNetworkReachabilityRef netReachability;
BOOL retrievedFlags = NO;
netReachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"http://www.google.com" UTF8String]);
if (netReachability) {
retrievedFlags = SCNetworkReachabilityGetFlags(netReachability, &flags);
CFRelease(netReachability);
}
if (!retrievedFlags || !flags) {
NSLog(@"no");
return NO;
}
NSLog(@"yes");
return YES;
}
非常感謝。我已經從「高級iOS編程」一書中獲得了我的代碼[1]。但Apple的Reachability Samplecode對我來說效果更好。謝謝你的提寶。你的,拉斐爾[1] http://www.amazon.de/Advanced-iOS-Programming-Applications-Application/dp/0470971231/ref=sr_1_1?ie=UTF8&s=books-intl-de&qid=1299947533&sr=8-1, – Raphael 2011-03-12 16:35:03
如果我的答案幫助您將其標記爲正確的答案。 – 2011-03-14 07:26:43