SWIFT:即使用户终止了应用程序,如何运行功能 [英] SWIFT: how to run a function even when user kills the app
问题描述
我正在将swift 2和Xcode7用于iOS9.我想知道我是否可以维持一个功能(该功能检查要删除的内容)即使用户杀死该应用程序也可以永远"运行?
I am using swift 2 and Xcode7 for iOS9. I want to know if I can maintain a function (that checks for something to delete) running "forever" even if the user kills the app?
我正在根据某些规则和时间从联系人列表中删除联系人.它运行正常,但仅在打开应用程序或处于第二个计划的情况下.我想让这个应用程序能够删除那些联系人,即使用户杀死了它.
I am deleting contacts from the contact list according to some rules and time. It is running ok, but just with the app opened or in second plan. I want to make this app capable to delete those contacts even when the user kills it.
推荐答案
您可以在用户打开应用程序时使用后台线程.但是,如果该应用程序将终止,则没有运行功能的选项. 在此处查找应用程序生命周期并重新设计您的体系结构: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html
You can use background thread when user opens the app. But if the app will be terminated, there is no option to run functions. Look for the app lifecycle here and redesign your architecture: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html
这篇关于SWIFT:即使用户终止了应用程序,如何运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!