状态我在viewController.m类下面的代码:可达性和IOS
- (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];
}
- 如何使用startNotifier?
- 我是否必须将这个放在每个视图控制器中,我想测试互联网连接?
我用这个来测试状态:
BOOL status = ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] != NotReachable);