我有以下代碼:你如何使用iPhone可達通知
- (void) testInternetConnection {
internetConnection = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is reachable
internetConnection.reachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Yayyy, we have the interwebs!");
});
};
// Internet is not reachable
internetConnection.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Someone broke the internet :(");
});
};
[internetConnection startNotifier];
}
我如何知道我的互聯網已經使用通知改變了嗎?我理解單例方法,並在需要時使用它。
是的,我正在使用該答案,但如何檢查一旦通知程序啓動? – cdub
使用kReachabilityChangedNotification –
並且即使當我關閉網絡時也是如此:BOOL status =([[Reachability reachabilityForInternetConnection] currentReachabilityStatus]!= NotReachable); – cdub