gpt4 book ai didi

iphone - 如何在后台应用程序时发送事件数据包 - IOS?

转载 作者:行者123 更新时间:2023-11-28 22:38:52 24 4
gpt4 key购买 nike

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

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

最佳答案

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

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.

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

关于iphone - 如何在后台应用程序时发送事件数据包 - IOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15129208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com