[TIMOB-26237] iOS: Local Notification Event not triggered when app is launched from the background
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-08-21T07:12:26.000+0000 |
Affected Version/s | Release 6.3.0, Release 7.1.1, Release 7.2.0 |
Fix Version/s | Release 7.3.1 |
Components | iOS |
Labels | localnotification, pushnotification |
Reporter | Matthew Delmarter |
Assignee | Hans Knöchel |
Created | 2018-07-24T01:47:02.000+0000 |
Updated | 2018-09-19T21:03:18.000+0000 |
Description
If a local notification is shown and the user taps the notification, the app opens, but the notification event is not triggered. It is triggered just fine if the app has already been opened but is not currently active in the foreground.
Sample code - the alerts are never fired if tapping the notification is staring up the app:
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT
]
});
Ti.App.iOS.addEventListener('notification', function(e) {
alert('notification');
});
Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
alert('localnotificationaction');
});
Ti.App.addEventListener('pause',function()
{
var timestamp = new Date(new Date().getTime() + 10000);
// The following code snippet schedules an alert to be sent within three seconds
var notification = Ti.App.iOS.scheduleLocalNotification({
category: "TEST",
alertAction: 'Read now',
alertBody: 'Custom message',
date: timestamp,
repeat: "daily",
//The following URL is passed to the application
userInfo: {
"task": "test"
}
});
});
Taken (and modified) from TIMOB-23527 (7.3.0), the following works fine:
Thanks for the quick reply Hans! To clarify (without having played with your code yet), does the link to TIMOB-23527 (7.3.0) mean that I need to wait for 7.3.0 for this to work? Or it should already work ok in 7.2.0 & 7.1.0 etc?
I tried with 7.3.0, but it's also supposed to work in <= 7.2.0. *EDIT*: Just tested with 7.2.0, works fine as well. Please compare the code to identify the issue for you. Thanks!
I am not having any luck here Hans. To be clear, the issue is about the notification event not being fired +from a fresh launch+. I have disabled the eventListener for *usernotificationsettings* as this always fires when the app is opened even if a notification has not been triggered. And from what I can see it is not relevant to a +specific+ notification being triggered by the user. Doing this step by step using your sample code... This process *works ok*: 1. Open the app 2. Click the "Trigger Notification" button 3. Home button once 4. Notification appears - click to Open. Note: Don't trigger the Accept/Reject/Respond, just tap the notification once to Open the app. 5. App opens and the alert "event: notification" appears This process *does not work*: 1. Open the app 2. Click the "Trigger Notification" button 3. Home button twice, to force close the app 4. Notification appears - click to Open. Note: Don't trigger the Accept/Reject/Respond, just tap the notification once to Open the app. 5. App opens - no alert is triggered I was testing with a clean app using 7.2.0 SDK. Can you let me know what is different for you? Does the second process, after a force close, work ok for you? Or am I missing something?
Hey there, you have been right! This is a quite edgy case that doesn't seem to be handled so far. I tested out a fix locally and it works fine. I will try to get it into 7.3.1 (as 7.3.0 is due next week already), but will also provide you a patch that you can apply today to test it out. More soon!
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10213 PR (7_3_X): https://github.com/appcelerator/titanium_mobile/pull/10215 Test-Case: In the comments above
Master merged, 7.3.1 will be merged once 7_3_X is bumped.
Verified fixed and changes are included in SDK builds 7.3.1.v20180821233955 & 7.4.0.v20180822015105
Unfortunately there is a bug with this fix. The fix is working perfectly, until one scenario... If the notification has the optional
sound
parameter set, then when the notification event is triggered, the following error is thrown... {noformat} [ERROR] Application raised an exception: -[UNNotificationSound boundBridge:withKrollObject:]: unrecognized selector sent to instance 0x600003336d00` {noformat} And the "localnotificationaction" event listener is not triggered. If the notification has the sound parameter removed, then everything works as expected. Unfortunately my app does have the sound parameter defined, and my users are well trained to hear the alert sound. If there is any chance this could be fixed as soon as possible I would be profoundly grateful :) To clarify here is the same notification as shown in the sample code above, but with the sound parameter defined:Further to my above comment, in same cases this error will crash the app.
I have created a new ticket for the issue: AC-5901