これは、アプリの到達可能性で使用するコードです。
- (void) handleNetworkChange:(NSNotification *)notice
{
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
if(remoteHostStatus == NotReachable) {
UIAlertView *alertnew = [[UIAlertView alloc] initWithTitle:@"No Internet Connection!" message:@"Your device lost internet connection!"
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:@"Dismiss", nil];
[alertnew show];
} else if (remoteHostStatus == ReachableViaWWAN) {
//if connected to the Network
UIAlertView *alertre = [[UIAlertView alloc] initWithTitle:@"Internet Connection!" message:@"Your device re-connected to the internet!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok!", nil];
[alertre show];
} else if (remoteHostStatus == ReachableViaWiFi) {
//if connected to Wi-Fi
UIAlertView *alertre = [[UIAlertView alloc] initWithTitle:@"Internet Connection!" message:@"Your device re-connected to the internet!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok!", nil];
[alertre show];
}
}
ユーザーがインターネットを失ったときと回復したときに警告したいと思います。しかし、私が直面している問題は、ユーザーが iPhone (常時ネットワーク接続) を使用していて、Wi-Fi に接続しているときに、既に接続されているときにアラートを受け取ることです。そのため、インターネット接続がなく、Wi-Fi に接続されていない場合にのみ、アラートを送信したいと思います。このコードは、データ プランのない iPod および iPad ではうまく機能しますが、問題は iPhone にあります。これを編集して、どちらか一方のアラートのみを表示するためにできることはありますか?
最後のアラートで次のコードを試しました。
else if (remoteHostStatus == ReachableViaWiFi && !(remoteHostStatus == ReachableViaWWAN)) {
//if connected to Wi-Fi but without Network
UIAlertView *alertre = [[UIAlertView alloc] initWithTitle:@"Internet Connection!" message:@"Your device re-connected to the internet!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok!", nil];
[alertre show];
}
しかし、これは問題を解決しませんでした...