[fcm] iOS 8/9 support
This commit is contained in:
parent
3e7a1efe4e
commit
b71a2c7aec
|
@ -52,10 +52,7 @@ RCT_EXPORT_MODULE()
|
|||
#endif
|
||||
|
||||
// Set static instance for use from AppDelegate
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
theRNFirebaseMessaging = self;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
|
@ -67,18 +64,20 @@ RCT_EXPORT_MODULE()
|
|||
// Listen for background messages
|
||||
- (void)didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
|
||||
BOOL isFromBackground = (RCTSharedApplication().applicationState == UIApplicationStateInactive);
|
||||
NSDictionary *message = [self parseUserInfo:userInfo clickAction:nil openedFromTray:isFromBackground];
|
||||
|
||||
// TODO: Format data before send
|
||||
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:userInfo];
|
||||
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:message];
|
||||
}
|
||||
|
||||
// Listen for background messages
|
||||
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo
|
||||
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
||||
BOOL isFromBackground = (RCTSharedApplication().applicationState == UIApplicationStateInactive);
|
||||
NSDictionary *message = [self parseUserInfo:userInfo clickAction:nil openedFromTray:isFromBackground];
|
||||
|
||||
// TODO: Format data before send
|
||||
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:userInfo];
|
||||
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:message];
|
||||
|
||||
// TODO: FetchCompletionHandler?
|
||||
}
|
||||
|
||||
// ** UNUserNotificationCenterDelegate methods **
|
||||
|
@ -105,9 +104,9 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|||
#endif
|
||||
NSDictionary *userInfo = [self parseUNNotification:response.notification openedFromTray:true];
|
||||
|
||||
// TODO: Format data before send
|
||||
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:userInfo];
|
||||
|
||||
// TODO: Validate this
|
||||
completionHandler();
|
||||
}
|
||||
|
||||
|
@ -209,22 +208,34 @@ RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic) {
|
|||
} else if ([k1 isEqualToString:@"from"]) {
|
||||
message[@"from"] = appData[k1];
|
||||
} else if ([k1 isEqualToString:@"notification"]) {
|
||||
NSDictionary *n = appData[k1];
|
||||
NSMutableDictionary *notification = [[NSMutableDictionary alloc] init];
|
||||
for (id k2 in appData[@"notification"]) {
|
||||
NSDictionary *notification = appData[k1];
|
||||
NSMutableDictionary *notif = [[NSMutableDictionary alloc] init];
|
||||
for (id k2 in notification) {
|
||||
if ([k2 isEqualToString:@"badge"]) {
|
||||
notification[@"badge"] = n[k2];
|
||||
notif[@"badge"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"body"]) {
|
||||
notification[@"body"] = n[k2];
|
||||
notif[@"body"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"body_loc_args"]) {
|
||||
notif[@"bodyLocalizationArgs"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"body_loc_key"]) {
|
||||
notif[@"bodyLocalizationKey"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"click_action"]) {
|
||||
notif[@"clickAction"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"sound"]) {
|
||||
notification[@"sound"] = n[k2];
|
||||
notif[@"sound"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"subtitle"]) {
|
||||
notif[@"subtitle"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"title"]) {
|
||||
notification[@"title"] = n[k2];
|
||||
notif[@"title"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"title_loc_args"]) {
|
||||
notif[@"titleLocalizationArgs"] = notification[k2];
|
||||
} else if ([k2 isEqualToString:@"title_loc_key"]) {
|
||||
notif[@"titleLocalizationKey"] = notification[k2];
|
||||
} else {
|
||||
NSLog(@"Unknown notification key: %@", k2);
|
||||
}
|
||||
}
|
||||
message[@"notification"] = notification;
|
||||
message[@"notification"] = notif;
|
||||
} else {
|
||||
// Assume custom data key
|
||||
data[k1] = appData[k1];
|
||||
|
@ -329,3 +340,4 @@ RCT_EXPORT_METHOD(unsubscribeFromTopic: (NSString*) topic) {
|
|||
@implementation RNFirebaseMessaging
|
||||
@end
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue