[TIMOB-17705] iOS8: Handle action types for Remote Notifications as well
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-09-19T21:25:11.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.4.0, Release 3.5.0 |
Components | iOS |
Labels | n/a |
Reporter | Timan Rebel |
Assignee | Jon Alter |
Created | 2014-09-16T14:27:57.000+0000 |
Updated | 2014-11-21T20:22:45.000+0000 |
Description
Currently only actions on Local Notifications are handled. We, as Titanium Developers, can display Remote Notifications with Actions, but a click on one of the buttons is never received by the app.
In TiApp.m the following is implemented for Local Notifications
- (void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:
See: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiApp.m#L441
A similar AppDelegate function has to be implemented to handle Actions on Remote Notifications
- application:handleActionWithIdentifier:forRemoteNotification:completionHandler:
See: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:handleActionWithIdentifier:forRemoteNotification:completionHandler:
I reckon that the implementation can be similar to
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
See: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiApp.m#L825
With in addition a key in the event details which action was triggered.
Will fire event named 'remotenotificationaction'
The local notifications trigger 'notification' or 'notificationbackground' (without the action part) and a remote notification triggers the callback registered when calling 'registerRemoteNotifications'. Can't you call the callback registered with registerRemoteNotifications or trigger 'remotenotification' and have every remote notification trigger that event as well? Now it seems inconsistent with how the rest of the notifications are handled.
I just noticed that the event for local notifications is now called localnotificationaction, so please disregard my comment.
master PR: https://github.com/appcelerator/titanium_mobile/pull/6129 3_4_X PR: https://github.com/appcelerator/titanium_mobile/pull/6130
Steps to test
1. Setup push (have fun with that) 2. Open the ti.cloud example app and make a new file in thepushNotifications
folder namedtest.js
with the contents below. 2.5. Include the ti.cloud module 3. Update table.js to include the file you just added (see table.js line 7 and 18 below) 4. Run the app 5. Go toPush Notifications>Settings
and clickdisabled
(if registering for push is successful, you will get an alert with the device token) 6. Go back one window and clickSubscribe Token
> fill in any channel name you like and then subscribe. 7. If this was successful, go to the dashboard, and send a push with one of the categories defined below. 8. You should see theremotenotificationaction
event fired when you click one of the buttons on the alert.test.js
table.js
Closing ticket as fixed. Verified ACS iOS push (remote notification) can trigger the notification actions on device. Tested on: Appcelerator Studio, build: 3.4.0.201409161950 SDK build: 3.4.0.v20140919142515 ti.cloud: 3.2.4 Dashboard: preproduction (2.0.1) CLI: 3.4.0-rc4 Alloy: 1.5.0-rc3 Xcode: 6.0.1 Devices: iphone 5s (8.0)
please reopen ... doesn't work if the app is not running !!! or not in background !! serious issue
[~pilo] Please file a set of steps to reproduce your issue and we'd be happy to take a look.
Like Perez Pilosof commented the action tapped by the user doesn't get fired when the app is not in memory (foreground or background). The steps described by Jon Alter all work except for step 8. The actions are shown on the notification center of course, but when tapping one of them it will just start the app but the 'remotenotificationaction' event is never fired. By adding some log statements to I found that in TiApp.m
is called before app.js gets loaded. So that's too soon to even register for the 'remotenotificationaction' event in your app.
A kind of dirty quick hack is to delay firing the event with this code (at about line 465 in TiApp.m of SDK 3.4.0):