Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-17705] (3_4_X)Adding remotenotificationaction event for handling when in... #6130

Merged
merged 4 commits into from
Sep 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 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,21 @@ 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 payload passed to the Apple Push Notification Service.
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
41 changes: 28 additions & 13 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 Expand Up @@ -1052,31 +1069,29 @@ -(void)stopBackgroundService:(TiProxy *)proxy
[self checkBackgroundServices];
}

#define NOTNULL(v) ((v==nil) ? (id)[NSNull null] : v)


#define NOTNIL(v) ((v==nil) ? (id)[NSNull null] : v)

+ (NSDictionary *)dictionaryWithLocalNotification:(UILocalNotification *)notification withIdentifier: (NSString *)identifier
{
if (notification == nil) {
return nil;
}
NSMutableDictionary* event = [NSMutableDictionary dictionary];
[event setObject:NOTNULL([notification fireDate]) forKey:@"date"];
[event setObject:NOTNULL([[notification timeZone] name]) forKey:@"timezone"];
[event setObject:NOTNULL([notification alertBody]) forKey:@"alertBody"];
[event setObject:NOTNULL([notification alertAction]) forKey:@"alertAction"];
[event setObject:NOTNULL([notification alertLaunchImage]) forKey:@"alertLaunchImage"];
[event setObject:NOTNULL([notification soundName]) forKey:@"sound"];
[event setObject:NOTNIL([notification fireDate]) forKey:@"date"];
[event setObject:NOTNIL([[notification timeZone] name]) forKey:@"timezone"];
[event setObject:NOTNIL([notification alertBody]) forKey:@"alertBody"];
[event setObject:NOTNIL([notification alertAction]) forKey:@"alertAction"];
[event setObject:NOTNIL([notification alertLaunchImage]) forKey:@"alertLaunchImage"];
[event setObject:NOTNIL([notification soundName]) forKey:@"sound"];
[event setObject:NUMINT([notification applicationIconBadgeNumber]) forKey:@"badge"];
[event setObject:NOTNULL([notification userInfo]) forKey:@"userInfo"];
[event setObject:NOTNIL([notification userInfo]) forKey:@"userInfo"];
//include category for ios8
if ([TiUtils isIOS8OrGreater]) {
[event setObject:NOTNULL([notification category]) forKey:@"category"];
[event setObject:NOTNULL(identifier) forKey:@"identifier"];
[event setObject:NOTNIL([notification category]) forKey:@"category"];
[event setObject:NOTNIL(identifier) forKey:@"identifier"];
}

return [[event copy] autorelease];
return event;

}
+ (NSDictionary *)dictionaryWithLocalNotification:(UILocalNotification *)notification
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