互联网在iOS上可用时的通知 [英] Notification when Internet became available on iOS

查看:114
本文介绍了互联网在iOS上可用时的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当互联网成为可能时,是否有可能在我的应用内收到通知或内容。我知道可达性和各种东西。但我想要的是当互联网在设备上可用时启动一些待定的NSUrlConnections。有没有一种简单的方法可以做到这一点,因为我不想使用循环线程来不断检查可达性。有什么建议吗?

Is it possible to receive a notification or something inside my app when the internet BECOMES available. I'm aware of reachability and all kinds of stuff. But what i want is to start some pending NSUrlConnections when internet becomes available on the device. Is there a easy way to do this, because I don't want to use a looping thread that checks constantly for reachability. Any suggestions?

推荐答案

好的,这里有关于可达性的非常好的帖子: http://www.mikeash.com/pyblog/friday-qa-2013-06-14-reachability.html (查看下面的评论!)

Tldr:你可以在连接恢复时触发阻止,但这个解决方案并不完美。没有100%可靠的方法来执行此操作(尝试循环除外),但您可以尝试混合这些方法。

Ok, here is very nice post about Reachability: http://www.mikeash.com/pyblog/friday-qa-2013-06-14-reachability.html (check comments below!)
Tldr: You can fire block when your connection is back, but this solution is not perfect. There is no 100% reliable way to do this (except trying in loop), but you can try to mix those approaches.

编辑:对@ Jonah.at的评论。 GoDaddy回答:

可达性可以给你两个连接通知错误:误报和漏报(你可以在WWDC 2011会议上查看,我不记得哪一个;有两个关于网络)。所以,我的观点是:你永远不应该只依赖那些通知。您可以触发刷新状态更改,但应该有另一种方法(用户交互或某种活动等待)。

Comment to @Jonah.at.GoDaddy answer:
Reachability can give you both connection notification errors: false positive and false negative (you can check it at WWDC 2011 session, I don’t remember which one; there are two about networking). So, my point is: you should never rely only on those notification. You can trigger refresh on status change, but there should be another way of doing it (user interaction, or some kind of active waiting).

这篇关于互联网在iOS上可用时的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆