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