iPhone应用程序在后台运行时如何接收异步网络消息
我有一个 iPhone 应用程序从服务器接收网络消息。当应用程序在前端运行时就可以了。
但是,当应用程序在后台运行时,应用程序不会接收网络消息。当我把它带回前端后,它开始接收。
如何让应用程序在后台运行时也能接收网络消息?
谢谢。
I have an iphone app receiving network message from server. It is ok when the app is running in frontend.
However, when the app is running in background, the app does not receive network message. After I bring it back to frondend, it starts receiving.
How to make the app can receive network message even it is running in background?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在后台时,您有两个网络连接选项:
推送通知。该应用程序未运行,但您的服务器可以请求发送通知,然后该通知将发送到 iPhone,提示用户启动您的应用程序,然后该应用程序可以通过常规请求从您的服务器进行自我更新。
后台网络调用。您的应用程序可以请求在后台保持线程处于活动状态,以便完成网络活动。您可以使用它在您的应用程序关闭时发送请求以检查您的服务器。
You've got two options for network connection while in the background:
Push Notifications. The app is not running, but your server can request to send a notification, which will then be sent to the iPhone, prompting the user to launch your app which can then update itself from your server thru a regular request.
Background network calls. Your app can request to keep a thread alive in the background in order to finish a network activity. You could use this to send a request when your app closes to check in with your server.
首先查看这篇文章:iphone - 在后台连接到服务器
其次,具体来说,当您的应用程序位于后台并被操作系统冻结时,它将无法访问互联网,因此您的应用程序不会听到来自异步请求的任何回调。
第三,一个可能的策略:
First check this post: iphone - Connecting to server in background
Second, specifically speaking, when you app is in the background and is frozen by the OS, it won't have access to the internet, thus any call back from an async request won't be heard by your app.
Third, a possible strategy:
我不是 iPhone 开发人员,但对我来说,对于所有后台应用程序,所有网络消息都应该推送到苹果服务器,然后推送到手机。没有像Android那样的服务。
I'm not an iphone dev but for me, for all background apps, all network messages should be push to apple server and then push to the phone. There is no service like in Android.