這是我在我的應用程序使用的可達性代碼:蘋果可達通知對網絡或Wi-Fi
- (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,但問題出在iPhones上。有什麼我可以做的編輯這個,並使其只顯示一個或另一個警報?
我嘗試此代碼爲最後警告:
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];
}
但這並沒有解決問題...
我可以在Stackoverflow中寫下我的問題,還是希望我使用您的網站 –