在Reachability中没有调用通知

Har*_*rsh 5 iphone reachability ios4

我使用过Andrew的修改后的Reachability类.

-(void)viewDidLoad

[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

下载数据时,我会AirPort关闭.但是checkNetworkStatus没有被召唤.我错过了什么.请帮我.这个问题让我疯了.提前致谢.

rck*_*nes 11

您是否告诉可达性实例开始广播通知?

Reachability *internetReachable = [Reachability reachabilityForInternetConnection];
// This will tell the notifier to start sending notifications
[internetReachable startNotifier];
Run Code Online (Sandbox Code Playgroud)

  • 另外需要注意的是静态方法reachabilityForInternetConnection始终创建Reachability对象的新实例.因此,请确保保留指向该指针的指针,否则您将不会收到更改通知,因为对象已经被释放. (8认同)

Vij*_*com 2

按照这个顺序

在你看来确实加载了

首先注册

然后

发布该通知

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];


[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];
Run Code Online (Sandbox Code Playgroud)