Skip to content

Commit

Permalink
[TIMOB-17705] Adding remotenotificationaction event for handling when…
Browse files Browse the repository at this point in the history
… interactive push notifications are clicked
  • Loading branch information
jonalter committed Sep 18, 2014
1 parent f53e7ed commit a9f3bcb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
22 changes: 21 additions & 1 deletion apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ events:
type: Dictionary

- name: localnotificationaction
summary: Fired when a user selects an action for an interactive notification.
summary: Fired when a user selects an action for an interactive local notification.
properties:
- name: alertAction
summary: |
Expand Down Expand Up @@ -331,6 +331,26 @@ events:
summary: Custom data object.
type: Dictionary

- name: remotenotificationaction
summary: Fired when a user selects an action for an interactive remote notification.
properties:
- name: data
summary: The `userinfo` dictionary passed to the Apple Push Notification Service.
description: |
For more information, see the following item in the iOS Developer Library:
[application:didReceiveRemoteNotification in the UIApplicationDelegate Protocol
Reference](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:)
type: Dictionary

- name: category
summary: Identifier of the category of the interactive notification.
type: String

- name: identifier
summary: Identifier of the action that was selected of the interactive notification.
type: String

- name: backgroundfetch
summary: Fired when the application is woken up for a fetch operation. Available only on iOS 7 and later.
description: |
Expand Down
17 changes: 17 additions & 0 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,23 @@ - (void) application:(UIApplication *)application handleActionWithIdentifier:(NS
completionHandler();
}

- (void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler {
RELEASE_TO_NIL(remoteNotification);
[self generateNotification:userInfo];
NSMutableDictionary *event = [[NSMutableDictionary alloc] init];
event[@"data"] = remoteNotification;
if (identifier != nil) {
event[@"identifier"] = identifier;
}
NSString *category = remoteNotification[@"category"];
if (category != nil) {
event[@"category"] = category;
}
[[NSNotificationCenter defaultCenter] postNotificationName:kTiRemoteNotificationAction object:event userInfo:nil];
[event autorelease];
completionHandler();
}

#pragma mark -

#pragma mark Helper Methods
Expand Down
30 changes: 21 additions & 9 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ -(void)_listenerAdded:(NSString*)type count:(int)count
if (count == 1 && [type isEqual:@"notification"]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:kTiLocalNotification object:nil];
}
if (count == 1 && [type isEqual:@"localnotificationaction"]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveBackgroundLocalNotification:) name:kTiLocalNotificationAction object:nil];
}
if (count == 1 && [type isEqual:@"localnotificationaction"]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotificationAction:) name:kTiLocalNotificationAction object:nil];
}
if (count == 1 && [type isEqual:@"remotenotificationaction"]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveRemoteNotificationAction:) name:kTiRemoteNotificationAction object:nil];
}

if ((count == 1) && [type isEqual:@"backgroundfetch"]) {
NSArray* backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
Expand Down Expand Up @@ -87,9 +90,12 @@ -(void)_listenerRemoved:(NSString*)type count:(int)count
if (count == 0 && [type isEqual:@"notification"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiLocalNotification object:nil];
}
if (count == 0 && [type isEqual:@"localnotificationaction"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiLocalNotificationAction object:nil];
}
if (count == 0 && [type isEqual:@"localnotificationaction"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiLocalNotificationAction object:nil];
}
if (count == 0 && [type isEqual:@"remotenotificationaction"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiRemoteNotificationAction object:nil];
}

if ((count == 1) && [type isEqual:@"backgroundfetch"]) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiBackgroundFetchNotification object:nil];
Expand Down Expand Up @@ -463,10 +469,16 @@ -(void)didReceiveLocalNotification:(NSNotification*)note
[self fireEvent:@"notification" withObject:notification];
}

-(void)didReceiveBackgroundLocalNotification:(NSNotification*)note
-(void)didReceiveLocalNotificationAction:(NSNotification*)note
{
NSDictionary *notification = [note object];
[self fireEvent:@"localnotificationaction" withObject:notification];
NSDictionary *notification = [note object];
[self fireEvent:@"localnotificationaction" withObject:notification];
}

-(void)didReceiveRemoteNotificationAction:(NSNotification*)note
{
NSDictionary *notification = [note object];
[self fireEvent:@"remotenotificationaction" withObject:notification];
}

-(void)didReceiveBackgroundFetchNotification:(NSNotification*)note
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ extern NSString * const kTiBackgroundTransfer;
extern NSString * const kTiFrameAdjustNotification;
extern NSString * const kTiLocalNotification;
extern NSString * const kTiLocalNotificationAction;
extern NSString * const kTiRemoteNotificationAction;
extern NSString * const kTiUserNotificationSettingsNotification;
extern NSString * const kTiBackgroundTransfer;
extern NSString * const kTiURLDownloadFinished;
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void TiLogMessage(NSString* str, ...) {
NSString * const kTiFrameAdjustNotification = @"TiFrameAdjust";
NSString * const kTiLocalNotification = @"TiLocalNotification";
NSString * const kTiLocalNotificationAction = @"TiLocalNotificationAction";
NSString * const kTiRemoteNotificationAction = @"TiRemoteNotificationAction";
NSString * const kTiUserNotificationSettingsNotification = @"TiUserNotificationSettingsNotification";

NSString* const kTiBehaviorSize = @"SIZE";
Expand Down

0 comments on commit a9f3bcb

Please sign in to comment.