Closed emilianoeloi closed 8 years ago
You need to update the PushNotificationDelegate methods -http://docs.urbanairship.com/reference/libraries/ios/latest/Protocols/UAPushNotificationDelegate.html
I believe you want something like this:
-(void)receivedBackgroundNotification:(UANotificationContent *)notificationContent completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (![self actionHandleNotification:notificationContent.notificationInfo completionHandler:completionHandler]) {
[[ReactNativeUAIOS getInstance] dispatchEvent:@"receivedNotification" body:@{@"event": @"receivedBackgroundNotificationActionButton",
@"data": notificationContent.notificationInfo}];
completionHandler(UIBackgroundFetchResultNoData);
}
}
-(void)receivedForegroundNotification:(UANotificationContent *)notificationContent completionHandler:(void (^)())completionHandler {
if (![self actionHandleNotification:notificationContent.notificationInfo completionHandler:completionHandler]) {
[[ReactNativeUAIOS getInstance] dispatchEvent:@"receivedNotification" body:@{@"event": @"receivedForegroundNotification",
@"data": notificationContent.notificationInfo}];
completionHandler();
}
}
-(void)receivedNotificationResponse:(UANotificationResponse *)notificationResponse completionHandler:(void (^)())completionHandler {
if (![self actionHandleNotification:notificationResponse.notificationContent.notificationInfo completionHandler:completionHandler]) {
if ([notificationResponse.actionIdentifier isEqualToString:UANotificationDefaultActionIdentifier]) {
[[ReactNativeUAIOS getInstance] dispatchEvent:@"receivedNotification" body:@{@"event": @"launchedFromNotification",
@"data": notification}];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:notification forKey:@"push_notification_opened_from_background"];
[defaults synchronize];
} else {
UANotificationAction *notificationAction = [self notificationActionForCategory:response.notificationContent.categoryIdentifier
actionIdentifier:response.actionIdentifier];
if (notificationAction.options & UNNotificationActionOptionForeground) {
[[ReactNativeUAIOS getInstance] dispatchEvent:@"receivedNotification" body:@{@"event": @"launchedFromNotificationActionButton",
@"data": notificationResponse.notificationContent.notificationInfo}];
} else {
[[ReactNativeUAIOS getInstance] dispatchEvent:@"receivedNotification" body:@{@"event": @"receivedBackgroundNotificationActionButton",
@"data": notificationResponse.notificationContent.notificationInfo}];
}
}
completionHandler();
}
}
+ (UANotificationAction *)notificationActionForCategory:(NSString *)category actionIdentifier:(NSString *)identifier {
NSSet *categories = [UAirship push].combinedCategories;
UANotificationCategory *notificationCategory;
UANotificationAction *notificationAction;
for (UANotificationCategory *possibleCategory in categories) {
if ([possibleCategory.identifier isEqualToString:category]) {
notificationCategory = possibleCategory;
break;
}
}
if (!notificationCategory) {
return nil;
}
NSMutableArray *possibleActions = [NSMutableArray arrayWithArray:notificationCategory.actions];
for (UANotificationAction *possibleAction in possibleActions) {
if ([possibleAction.identifier isEqualToString:identifier]) {
notificationAction = possibleAction;
break;
}
}
return notificationAction;
}
I have to run for the day, but I can follow up tomorrow if you need more help. I was unable to test it and I am sure you can simplify the notificationResponse method.
Great! Thank you, Mr. Lepinski.
@emilianoeloi https://github.com/emilianoeloi/react-native-ua/pull/1
@emilianoeloi - You can also provide default presentation options on UAPush .
We did not add support for the options in UAConfig, but you could have the plugin look for some flags in the customConfig
section of AirshipConfig and set the default options for the plugin.
iOS 10 support #22 urbarAirshipSDK 8.0.1