[TIMOB-3528] iOS: Distinguishing between remote push notifications
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-02-13T23:55:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.1.0, 2013 Sprint 04 API, 2013 Sprint 04 |
Components | iOS |
Labels | CLA, defect, ios, notifications, push, rplist |
Reporter | Alan Leard |
Assignee | Sabil Rahim |
Created | 2011-04-15T03:46:20.000+0000 |
Updated | 2017-03-21T18:25:44.000+0000 |
Description
Problem
When an app is running and a remote push notification is received, the callback passed to Ti.Network.registerForPushNotifications is called. This is fine.
When an app is NOT running and a remote push notification is received, if the user taps "View" to open the app, the callback is also called, but NOTHING is included in the event to indicate that this notification was already displayed to the user and the app was launched via the "View" button. Thus, the app displays the notification that the user has already seen.
There are three possible cases:
- App just launched (by tapped the action button (named "View" by
default) in the notification presented by iOS.
- App made active (brought from background to foreground, again
by the action button).
- App already running (in foreground).
Suggested Obj-C Fix
FROM:
// check to see upon registration if we were started with a push
// notification and if so, go ahead and trigger our callback
id currentNotification = [[TiApp app] remoteNotification];
if (currentNotification!=nil && pushNotificationCallback!=nil)
{
id event = [NSDictionary dictionaryWithObject:currentNotification forKey:@"data"];
[self _fireEventToListener:@"remote" withObject:event listener:pushNotificationCallback thisObject:nil];
}
TO:
// check to see upon registration if we were started with a push
// notification and if so, go ahead and trigger our callback
id currentNotification = [[TiApp app] remoteNotification];
if (currentNotification!=nil && pushNotificationCallback!=nil)
{
id event = [NSDictionary dictionaryWithObjectsAndKeys:currentNotification, @"data", NUMBOOL(YES), @"firedFromRegister", nil];
[self _fireEventToListener:@"remote" withObject:event listener:pushNotificationCallback thisObject:nil];
}
See Ticket Reference for more Detail: http://support.appcelerator.com/tickets/EBJ-28594-463">http://support.appcelerator.com/tickets/EBJ-28594-463
Not contesting this would be a cute feature request, but I do have to point out a few things: The property name is confusing. There is no 'register' per se, one registers with the servers, but that happens regardless of the notification being fired while the application was in the foreground or background. Perhaps a better name for the property might be 'inBackground'. Also, note that the different native codepaths depend on if the app was resident in memory. In other words, if the app is backgrounded and then relaunched, the logic suggested would falsely report the application was not in the background due to it not having been unloaded from memory. Finally, the reason for the request worries me. Applications should not show dialog boxes due to push or local notifications, they should only silently update what's needed. There is a reason that push notifications went from feature to throttled feature to throttled feature that can be disabled. The author of the ticket should reconsider his UI regarding notifications, regardless of when this issue is resolved.
Fixed by PR: https://github.com/appcelerator/titanium_mobile/pull/3869 Introduced new arg to the remote event fired in response to push notification. For testing instructions check PR
Closing ticket as fixed.