1

I'm working on a iOS application in which I need to perform a task in the app everyday at 8am. I need to perform that task in all the below three conditions of app which are,

  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 (i.e. app is terminated).

I've handled the case 1 and case 2 but I've no idea how to handle the case 3. Please help. Thanks in advance.

Rahul Bansal
  • 1,382
  • 15
  • 22
  • 1
    what kind of task you have to perform in background ?? based on that you need to enable background flag in info.plist with specific type. – CodeChanger Nov 17 '16 at 10:05
  • @CodeChanger I need to perform a local database calculation in background and on its result, I need to schedule a local notification. – Rahul Bansal Nov 17 '16 at 10:07
  • based on my experience there are 9 types of background modes and among that your requirement not fit in any of the mode you need to go with either remote notification update or need to call some service based on DB result. – CodeChanger Nov 17 '16 at 10:11
  • @CodeChanger My app doesn't support remote notifications so that won't work. How can I do the other thing which you mentioned "call some service based on DB result"? Also will it awake the app if it is terminated? – Rahul Bansal Nov 17 '16 at 10:26

1 Answers1

0

You can use PushKit ( Silent push notification ).

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.

In kill state your app will wake up in background for max 30 seconds ( As much your local notification sound file plays ).

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.

UI related work doesn't happen here.

Refer

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

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

Hasya
  • 9,792
  • 4
  • 31
  • 46
  • thanks for your answer. In the above raywenderlich link, I've found that there is a limitation of Silent push notifications which is, if user manually force quits the app then the app will not be awake or perform any task in background until user manually opens the app again. – Rahul Bansal Nov 17 '16 at 10:55
  • Dont worry, i have worked on such app, forcefully killed app will get open. check my answers mostly on VOIP, Pushkit, background etc. – Hasya Nov 17 '16 at 11:01
  • can you use pushkit for location services or it is used only for voip services ?? – Tejvansh Mar 15 '17 at 20:43
  • @TejvanshsinghChhabra I have used only for VOIP app, but if you are is in specific category and prior permission from Apple, then you can use for other purposes as well. – Hasya Mar 16 '17 at 04:53