为什么我的警报显示两次?
|
在我的应用程序中,我检查到我的网站的当前连接状态以及应用程序启动时的网络状态:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification object:nil];
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifier];
hostReach = [[Reachability reachabilityWithHostName:@\"www.google.de\"]
retain];
[hostReach startNotifier];
[self updateInterfaceWithReachability:internetReach];
[self updateInterfaceWithReachability:hostReach];
//....
-(void)reachabilityChanged: (NSNotification* )note{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
在我的“ 1”中,如果无法建立与网站的连接,我想显示一个警报。
我的问题是警报显示了两次,所以第一次出现,而当我关闭它时,则显示秒:
if(curReach == hostReach){
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if(netStatus != NotReachable){
statusLabel.text = @\"connected\";
[self setStatusColorGreen];
}else{
if(![internetReach connectionRequired]){
statusLabel.text = @\"not connected\";
compose.enabled = NO;
[self doSMSFAlert];
[self setStatusColorRed];
}
}
}
有任何想法吗?
编辑:我现在注意到我有一个正在工作的主机,警报也会显示,但它不应该显示。但是状态为“已连接”
没有找到相关结果
已邀请:
2 个回复
漂汀拦
讹巳漓把备