在后台应用程序时如何发送活动包 - IOS?

时间:2013-02-28 06:46:04

标签: iphone ios cocoa-touch nsthread uiapplicationdelegate

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

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

您的应用程序永远不会始终在ios中运行。你需要从推送通知中获取帮助。即使您使用一个插槽,我也不认为它会运行超过预定义的时间。所有voip app都跟随推送通知。

Refer this link

    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. 

注意:大多数虚拟应用程序都像用户发送一个消息一样,服务器向接收方发送推送通知,如果接收方响应推送通知,则处理消息。当用户不响应推送通知时,Twist会出现。这是在启动应用程序时处理的,用户应用程序在服务器中查询任何消息,然后在应用程序界面中显示消息。希望这个逻辑可以帮助你。