Reachability 中未调用通知

发布于 2024-11-26 22:23:02 字数 463 浏览 4 评论 0原文

我使用了 Andrew's 修改后的 Reachability 类。

-(void)viewDidLoad

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

下载数据时,我关闭 AirPort。但是 checkNetworkStatus 没有被调用。我是不是错过了什么。请帮我。这个问题让我发疯。提前致谢。

I have used Andrew's modified Reachability class.

-(void)viewDidLoad

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

When data is downloading I turn AirPort off. But checkNetworkStatus is not being called. Am I missing something. Please help me. This problem driving me nuts. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

放飞的风筝 2024-12-03 22:23:02

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

Reachability *internetReachable = [Reachability reachabilityForInternetConnection];
// This will tell the notifier to start sending notifications
[internetReachable startNotifier];

Did you tell the reachability instance to start broadcasting notifications?

Reachability *internetReachable = [Reachability reachabilityForInternetConnection];
// This will tell the notifier to start sending notifications
[internetReachable startNotifier];
野却迷人 2024-12-03 22:23:02

将其按此顺序放入

您的视图中并加载

首先注册

然后

发布该通知

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


[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];

put it in this sequence

in ur view did load

First register

then

post that notification

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


[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:nil];
本王不退位尔等都是臣 2024-12-03 22:23:02

我有完全相同的问题,Apple 的示例效果很好,所以我最终用 Apple 的版本替换了 Reachability 类,一切都很好。这花了我将近2个小时。

只需替换 Apple 示例中的 Reachability.h、.m,一切就应该可以正常工作。

I have exactly the same issue, Apple's example works great, so I end up replace Reachability class with Apple's version, everything works great. This costed me almost 2 hours.

Simply replace your Reachability.h, .m from Apple's example, everything should just worked.

傲性难收 2024-12-03 22:23:02

这对我有用(斯威夫特):

func handleNetworkChange(notification:NSNotification) { ... }

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("handleNetworkChange:"), name: kReachabilityChangedNotification, object: nil)
ReachabilityChecker = Reachability.reachabilityForInternetConnection()
ReachabilityChecker!.startNotifier()

This worked for me (Swift):

func handleNetworkChange(notification:NSNotification) { ... }

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("handleNetworkChange:"), name: kReachabilityChangedNotification, object: nil)
ReachabilityChecker = Reachability.reachabilityForInternetConnection()
ReachabilityChecker!.startNotifier()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文