【发布时间】:2013-08-05 17:44:14
【问题描述】:
我正在使用这个库来在设备上的连接状态发生变化时得到通知。我不明白为什么这不起作用!我正在做的正是我在 github 的文档中阅读的内容!
当应用程序启动时,通知会被发布,但是当我打开设置,打开/关闭飞行模式并返回应用程序(不关闭它)时,通知不会被调用。
我还订阅了获取 UIApplicationWillEnterForegroundNotification 通知...这两种方法都存在于应用程序中...我错过了什么吗?!?
这是在我看来DidLoad:
self.reach = [Reachability reachabilityWithHostname:kServerURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChangedInApp:)
name:kReachabilityChangedNotification
object:nil];
[self.reach startNotifier];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(initializeDateRelatedStuff:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
这是在我的交易中
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
谢谢!!
【问题讨论】:
-
kServerURL 是 NSString 吗?另外,reachabilityChangedInApp: 的代码是什么?
-
是的,它是一个带有谷歌 URL 的 NSString。它只是一个调用一些网络相关方法的函数。
标签: ios cocoa-touch reachability