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 fd02ba4 commit 4af12ef
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
14 changes: 13 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,18 @@ events:
summary: Custom data object.
type: Dictionary

- name: remotenotificationaction
summary: Fired when a user selects an action for an interactive remote notification.
extends: PushNotificationData
properties:
- 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
13 changes: 13 additions & 0 deletions iphone/Classes/TiApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,19 @@ - (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];
if (identifier != nil) {
NSMutableDictionary *mutableRemoteNotification = [[NSMutableDictionary alloc] initWithDictionary:remoteNotification];
mutableRemoteNotification[@"identifier"] = identifier;
RELEASE_TO_NIL(remoteNotification);
remoteNotification = mutableRemoteNotification;
}
[[NSNotificationCenter defaultCenter] postNotificationName:kTiRemoteNotificationAction object:remoteNotification userInfo:nil];
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 4af12ef

Please sign in to comment.