简体   繁体   English

当app处于后台或处于终止(终止)状态时,在iOS应用中执行任务

[英]Perform task in iOS app when app is in background or in terminated (killed) state

I'm working on a iOS application in which I need to perform a task in the app everyday at 8am. 我正在开发一个iOS应用程序,我需要每天早上8点在应用程序中执行任务。 I need to perform that task in all the below three conditions of app which are, 我需要在app的以下三个条件中执行该任务,

  1. If app is running in the foreground. 如果应用程序在前台运行。
  2. If app is running in the background. 如果应用程序在后台运行。
  3. If app is neither running in the foreground nor in background (ie app is terminated). 如果app既不在前台运行也不在后台运行(即app终止)。

I've handled the case 1 and case 2 but I've no idea how to handle the case 3. Please help. 我已经处理了案例1和案例2,但我不知道如何处理案件3.请帮忙。 Thanks in advance. 提前致谢。

You can use PushKit ( Silent push notification ). 您可以使用PushKit(无声推送通知)。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification https://github.com/hasyapanchasara/PushKit_SilentPushNotification

That notification doesn't come in notification center. 该通知不在通知中心。

But you can keep data ( As API ) in localNotification.UserInfo and schedule local notification. 但您可以将数据(As API)保存在localNotification.UserInfo中并安排本地通知。

In kill state your app will wake up in background for max 30 seconds ( As much your local notification sound file plays ). 在kill状态下,您的应用程序将在后台唤醒最多30秒(尽可能多的本地通知声音文件播放)。

You can do relevant thing in 30 seconds, as well tapping on interactive localNotification button you can again wake up app in background and do DB related work. 您可以在30秒内完成相关操作,同时点击交互式localNotification按钮,您可以再次在后台唤醒应用程序并执行与数据库相关的工作。

UI related work doesn't happen here. 与UI相关的工作不会在这里发生。

Refer 参考

https://www.raywenderlich.com/123862/push-notifications-tutorial https://www.raywenderlich.com/123862/push-notifications-tutorial

https://zeropush.com/guide/guide-to-pushkit-and-voip https://zeropush.com/guide/guide-to-pushkit-and-voip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM