0

Within iOS, upon receiving a notification in the lock screen, I need a background service within my app to start up.

I know this can occur in Android, but is this possible within iOS?

Sauron
  • 6,399
  • 14
  • 71
  • 136
  • What is "a background service"? – matt Dec 04 '16 at 01:20
  • @matt he probably refers to a background task to initiate when a remote notification is received. – Alejandro Iván Dec 04 '16 at 01:20
  • For example, a part of my application will start up given the push notification that was sent.@AlejandroIván, correct – Sauron Dec 04 '16 at 01:20
  • @AlejandroIván But if he receives a notification, he _is_ running in the background. – matt Dec 04 '16 at 01:21
  • @matt true, but if the app is closed, the notification will also be passed? So the app runs automatically in the background? That sounds like the issue. – Alejandro Iván Dec 04 '16 at 01:22
  • I think the issue (and question) is pretty much the same as this: http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user – Alejandro Iván Dec 04 '16 at 01:23

2 Answers2

1

If the user taps the notification alert, your app is sent an event in the background and is now running in the background (and you can even require that this means your app is brought to the foreground).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • There are WWDC 2016 videos on notifications, which have been heavily revamped for iOS 10. I would recommend watching them. – matt Dec 04 '16 at 01:25
1

The equivalent of an Android service does not exist in iOS.

There are two types of push, one that is sent to the app and one that is sent to the user.

If a push is sent to the user then:
- if your app is terminated, the push is displayed to the user
- if your app is in the background, the push is displayed to the user
- if your app is in the foreground, the push is delivered to the app.
If a push is sent to the app then:
- if your app is terminated, the push goes nowhere
- if your app is in the background, the push is sent to the app, and you *may* be able to perform some activity at that point, depending upon your background modes.
- if your app is in the foreground, the push is sent to the app.

(In addition to that, in iOS 10, pushes directed to the user can be intercepted and their content changed before they are displayed to the user. But they are not intercepted by your app, they are intercepted by an extension that is part of your app. But this does not mean you app can run at this point.)

So the answer to your question is no, because services do not exist. The answer to if you can run in the background when a app push is sent, is only if the app is not terminated and you have certain background capabilities. Due to the termination factor, it is not therefore a mechanism you can rely on.

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378