0

我正在开发一个 voip 应用程序,即使应用程序进入后台,我也需要始终保持与服务器的连接,苹果正在提供使用通信套接字的支持,我的问题是我有一个单独的服务器(即考虑登录服务器)我想发送每 1 分钟确认一次该服务器,我想我不能在后台为应用程序运行两个通信套接字。在那种情况下,我该如何发送 ack?

我已经从 applicationDidEnterBackground 分离了一个线程,它也将暂停,我的问题的解决方案是什么?任何的想法?

4

2 回答 2

1

您提出的建议将非常耗电(收音机永远不会空闲)。这在 App Store 应用程序中是不允许的。

您需要通过推送通知从服务器获取信息。

于 2013-02-28T07:07:34.677 回答
1

你的应用程序永远不会一直在 ios 中运行。你需要从推送通知中获得帮助。即使您使用一个套接字,我认为您的运行时间也不会超过预定义的时间。所有 voip 应用程序都遵循其中的推送通知。

参考这个链接

    Declaring Your App’s Supported Background Tasks

    Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings:
 - audio—The app plays audible content to the user while in the
   background. (This content includes streaming audio or video content
   using AirPlay.)
 - location—The app keeps users informed of their location, even while
   it is running in the background.
 - voip—The app provides the ability for the user to make phone calls
   using an Internet connection.
 - newsstand-content—The app is a Newsstand app that downloads and
   processes magazine or newspaper content in the background.
 - external-accessory—The app works with a hardware accessory that needs
   to deliver updates on a regular schedule through the External
   Accessory framework.
 - bluetooth-central—The app works with a Bluetooth accessory that needs
   to deliver updates on a regular schedule through the Core Bluetooth
   framework.
 - bluetooth-peripheral—The app supports Bluetooth communication in
   peripheral mode through the Core Bluetooth framework.

    Each of the preceding values lets the system know that your app should be woken up at appropriate times to respond to relevant events. For example, an app that begins playing music and then moves to the background still needs execution time to fill the audio output buffers. Including the audio key tells the system frameworks that they should continue playing and make the necessary callbacks to the app at appropriate intervals. If the app does not include this key, any audio being played by the app stops when the app moves to the background. 

注意:大多数无效应用程序的工作方式就像用户发送一条消息,服务器向接收者发送推送通知,如果接收者响应推送通知,则处理消息。当用户不响应推送通知时,就会出现扭曲。这是在启动应用程序时处理的,用户应用程序查询其服务器以获取任何味精,然后该味精会显示在应用程序界面中。希望这个逻辑对你有所帮助。

于 2013-02-28T07:13:04.847 回答