Problem with local notifications when app is in the background

In the simulator, when the app is in the background notifications are sent to the iOS Notification Center.

From the docs:

When a notification arrives, how your app handles it depends on whether the app is in the foreground or not. If your app is in the foreground, the NotificationCenter.NotificationReceived event will be called and you can return a value that describes how you wish the notification to be presented to the user. If your app is in the background or not running at all, the OS will display the notification. When the user taps on it, only then will your app’s NotificationCenter.NotificationReceived event will be called.

Tapping a notification will open the app but it seems that NotificationCenter.NotificationReceived is not called.
Making it impossible to respond to notifications.

<https://xojo.com/issue/64452>

Has anyone else experienced this?

I believe this is only for local notifications:
https://documentation.xojo.com/api/mobile/mobilenotifications.html#mobilenotifications-notificationreceived

Tried the other events ?
https://documentation.xojo.com/api/mobile/mobilenotifications.html#mobilenotifications-backgroundnotificationreceived

And the NotificationCenter.* seems to have become MobileNotifications.* (API 2.0) ?

Updated topic title to reflect that the issue is for local notifications. I haven’t tested remote notifications yet.

MobileNotifications object is called NotificationCenter in the Navigator :slight_smile:

1 Like

I’m getting them here. I’ll take a minute and put an example together.

Ok, so if a notification is received while your app is in the background (or the foreground and you return a PresentationMode which results in the notification being shown) and the user just taps the notification, your app is brought to the foreground and the UserResponded event fires with the Action parameter set to “com.apple.UNNotificationDefaultActionIdentifier”.

If you’ve defined specific actions and the user long-presses the notification and chooses one of the options, the app is not brought to the foreground but the UserResponded event still fires. In this case you have a very short time to process the data ( currently about 30 seconds, as defined by the OS ).

Does that answer your question?

Edit: Updated time to respond to notifications.

I’ll get the docs fixed.

2 Likes

Yes, and it works. Thanks!!