gpt4 book ai didi

医疗保健应用程序的 iOS 后台执行

转载 作者:可可西里 更新时间:2023-11-01 01:36:42 25 4
gpt4 key购买 nike

我需要实现以下要求:

iOS 应用程序应定期(例如:每 1 小时)从健康应用程序收集数据,并在后台模式下将数据发送到服务器。

我尝试像下面这样实现这个场景:

我实现了以下代码:-

func applicationDidEnterBackground(应用程序:UIApplication){

    self.bgTask = application.beginBackgroundTaskWithName("updateMedicalData") {
self.endBackgroundUpdateTask()

}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)) {
print("Time remaining ::",application.backgroundTimeRemaining)
NSTimer.scheduledTimerWithTimeInterval(25, target:self, selector:#selector(self.performBackgroundTask), userInfo:nil, repeats:true)
}


}

我已经在方法“performBackgroundTask()”中实现了从健康应用程序获取数据并发送服务器的逻辑

但问题是,App 仅在后台运行了 3 分钟,并调用了过期处理程序。

我已在 plist 文件中将键“必需的后台模式”设置为“应用程序从网络下载内容”,并将键“应用程序不在后台运行”设置为“否”。

谁能告诉我是否可以实现上述要求?

最佳答案

只有某些类型的应用程序可以有更长的后台执行时间。更具体:

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP)
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

请查看此链接,看看这是否适合您。我想“后台获取”可能适合您的需要。在这种情况下,您需要将 UIBackgroundModes 值设置为“fetch”。你已经这样做了吗?

祝你好运!

关于医疗保健应用程序的 iOS 后台执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36622612/

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