1

当设备上的连接状态发生变化时,我正在使用这个库来获得通知。我不明白为什么这不起作用!我正在做的正是我在 github 的文档中阅读的内容!

当应用程序启动时,通知会被发布,但是当我打开设置时,打开/关闭飞行模式并返回应用程序(不关闭它)不会调用通知。

我还订阅了获取 UIApplicationWillEnterForegroundNotification 通知...这两种方法都存在于应用程序中...我错过了什么吗?!?

这是在我的 viewDidLoad 中:

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];
}

谢谢!!

4

1 回答 1

2

The thing is that your application is most likely not a background application and thus suspended once you press the home button to activate airplane mode. Since your app is not running when the reachability changes, it won't get any notification. You will get the notification, however, when network reachability changes while your app is in foreground.

So you probably want to check the reachability when your app enters the foreground in addition to what you have already implemented.

于 2013-08-05T18:54:49.973 回答