所以我让警报视图检测是否存在活动的互联网连接。
这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
Reachability * reach = [Reachability reachabilityWithHostname:@"www.google.com"];
reach.reachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
blockLabel.text = @"";
});
};
reach.unreachableBlock = ^(Reachability * reachability)
{
dispatch_async(dispatch_get_main_queue(), ^{
blockLabel.text = @"You are not connected to the Internet";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please connect to Internet"
message:nil
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[alert show];
});
};
[reach startNotifier];
// Do any additional setup after loading the view, typically from a nib.
}
所以我的应用程序检测是否有互联网连接。但问题是,如果我在 iPhone 上打开互联网并打开应用程序,它仍然说没有互联网连接。我该怎么办……</p>