4

I have started experimenting with the new remote notification service in iOS 7. The interesting part, from the documentation is from UIApplication Delegate protocol.

If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method.

However, when i send a silent remote notification with the key "content-available" and a payload of "1", the app is not launched into background mode. If my app is in background mode or suspended, the notification is delivered to the app.

Is the documentation wrong?

dertkw
  • 7,798
  • 5
  • 37
  • 45
Trj
  • 657
  • 9
  • 21
  • 2
    Have you added `remote-notification` to your UIBackgroundModes Info PList entry? – David Snabel-Caunt Oct 15 '13 at 11:07
  • Yes, its added via XCodes new "Capabilities" feature. I have also double checked the file and the key and value is present – Trj Oct 15 '13 at 11:12
  • If you send a push with an alert message, do you see the message/is the push received? If not, it suggests that your app isn't launched because there's an issue with push in general. – David Snabel-Caunt Oct 15 '13 at 11:19
  • If i send a normal alert push, it gets displayed. So regular push is working just fine. I tried rebooting my device and remote notifications wasn't received then either, even though it was present in multitasking menu – Trj Oct 15 '13 at 11:23
  • I think apple has wrong documentation. Please refer apple forum https://devforums.apple.com/message/873265#873265. According to that remote-notification will work in background/foreground/suspended state. It won't work in "not-running" state. – Nandha Oct 15 '13 at 11:49
  • I have seen that post, but it seems weird that Apple don't update the documentation. Also, this feature was highlighted in the wwdc talk about multitasking. So if your app has to be running in the background for this to work, it's not that great of a feature. – Trj Oct 15 '13 at 12:32
  • It definitely works in not-running, that's the whole point of the feature. You can verify this in a working app by looking at the device console in Xcode's organizer for logs. Note also that you can send a remote notification that isn't silent, i.e. with an alert and a `content-available` value. This will make your debugging a little easier. You might also find my article on [Remote Notifications](http://www.objc.io/issue-5/multitasking.html#remote_notifications) useful. – David Snabel-Caunt Oct 15 '13 at 12:42
  • 1
    @DavidCaunt, I tried by sending remote-notification with alert message. I am receiving message in the app, however doesn't open the app. I need to tap the received alert to open our app. – Nandha Oct 15 '13 at 13:49
  • 1
    @DavidCaunt I created a new app, a new certificate and the whole routine. It still will not load the app when my app is in a state of not running. So, just to clarify, when you say "not running", what do you actually mean? If you kill your app by using the new multitask menu and swipe up so the app is killed. Do you still receive remote push notifications? And does iOS still wake up your app and let it execute code? – Trj Oct 15 '13 at 16:57
  • As I understand it, if you swipe up, iOS infers that the user doesn't want that app to multitask, and remote notifications *will not* work. If you stop the app with Xcode, and then send a notification, you should see activity in the device console via Xcode's Organizer window. – David Snabel-Caunt Oct 15 '13 at 17:02
  • 1
    Yes, that's exactly it, but then the app wont be in a state of "not running". The app will have a state of "background" or "suspended" according to the apple docs. https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html So then the apple documentation is fawlty. The app will not be notified and launched from all states. – Trj Oct 15 '13 at 17:08
  • It won't be running if you stop it from Xcode. Then when you send a remote notification, iOS launches the app in the background. Put some logging in your `application: didFinishLaunchingWithOptions:` and remote notification handler. – David Snabel-Caunt Oct 15 '13 at 17:21
  • Yes, well the point is that the feature is not at all so useful as it seems. And the documentation is deficient, at best. For instance, if the phone reboots, the app wont receive remote push notifications. And, from what i've learned now, the app wont receive remote push if the user kills the app (which i guess a lot of users do). If a user kills the app, there is no way to notify the user via a local push either that the app wont receive remote push. – Trj Oct 15 '13 at 17:34
  • 1
    @DavidCaunt If we stop app from xcode, the app will be in "suspended" state. Myself and Trj are saying that remote-notification is working only when the app is background/foreground/suspended state. Thats why Trj saying that apple doc is wrong. – Nandha Oct 15 '13 at 18:30
  • possible duplicate of [iOS 7 Background Fetch by Push Notification - Will iOS launch my app if it is not in the background?](http://stackoverflow.com/questions/19068762/ios-7-background-fetch-by-push-notification-will-ios-launch-my-app-if-it-is-no) – Eran Oct 15 '13 at 18:41
  • To enable background remote notification: http://stackoverflow.com/a/27816850/1603234 – Hemang Jan 07 '15 at 10:12

2 Answers2

0

Apple doc is a little confusing when it comes to remote notifications.
If your app was terminated by the user, or your device was rebooted, the notification won't be delivered.

"content-available" only wakes up your app if it was in background, or the app was killed by the system due to memory pressure.

Gautam Jain
  • 2,913
  • 30
  • 25
0

Adding/updating documentation, since I agree completely with Guatam Jain. The force quit is what threw me--Apple can't tell the difference between a developer doing testing and a user "cleaning up their phone" or manhandling a misbehaving app.

From https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html, section titled "Understanding When Your App Gets Launched into the Background" (emphasis mine):

Apps that support background execution may be relaunched by the system to handle incoming events. If an app is terminated for any reason other than the user force quitting it, the system launches the app when one of the following events happens: ... For background download apps: A push notification arrives for an app and the payload of the notification contains the content-available key with a value of 1.

Eliot Gillum
  • 832
  • 9
  • 18