diff --git a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java index dcf5b4921b5da7991a86af55ea0cfa9358ff4ac1..1b5077ac1c619f8e09c6a27696c8f7a371937b03 100644 --- a/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java +++ b/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java @@ -100,7 +100,7 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li } @ReactMethod - public void deleteFCMToken(Promise promise) { + public void deleteEntityFCMToken(Promise promise) { try { String senderId = FirebaseApp.getInstance().getOptions().getGcmSenderId(); FirebaseInstanceId.getInstance().deleteToken(senderId, "FCM"); diff --git a/index.js b/index.js index 0b541056df991c9f4fa0c6e43ede49e99336f5fc..731fbab2f25f832a076d4d7dc019848c555f3acc 100644 --- a/index.js +++ b/index.js @@ -72,8 +72,8 @@ FCM.getEntityFCMToken = () => { return RNFIRMessaging.getEntityFCMToken(); } -FCM.deleteFCMToken = () => { - return RNFIRMessaging.deleteFCMToken(); +FCM.deleteEntityFCMToken = () => { + return RNFIRMessaging.deleteEntityFCMToken(); } FCM.deleteInstanceId = () =>{ diff --git a/ios/RNFIRMessaging.m b/ios/RNFIRMessaging.m index 507b975eacaead3c045099c8157b65d5b3016059..3a8a5650cf7250fb859a6389a40c9e423ded7b85 100644 --- a/ios/RNFIRMessaging.m +++ b/ios/RNFIRMessaging.m @@ -140,7 +140,7 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) { + (UNNotificationAction *) UNNotificationAction:(id)json { NSDictionary *details = [self NSDictionary:json]; - + NSString *identifier = [RCTConvert NSString: details[@"id"]]; NSString *title = [RCTConvert NSString: details[@"title"]]; UNNotificationActionOptions options = [RCTConvert UNNotificationActionOptions: details[@"options"]]; @@ -152,11 +152,11 @@ typedef NS_ENUM(NSUInteger, UNNotificationActionType) { return [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:options textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder]; } - + return [UNNotificationAction actionWithIdentifier:identifier title:title options:options]; - + } RCT_ENUM_CONVERTER(UNNotificationActionType, (@{ @@ -180,9 +180,9 @@ RCT_MULTI_ENUM_CONVERTER(UNNotificationActionOptions, (@{ + (UNNotificationCategory *) UNNotificationCategory:(id)json { NSDictionary *details = [self NSDictionary:json]; - + NSString *identifier = [RCTConvert NSString: details[@"id"]]; - + NSMutableArray *actions = [[NSMutableArray alloc] init]; for (NSDictionary *actionDict in details[@"actions"]) { [actions addObject:[RCTConvert UNNotificationAction:actionDict]]; @@ -261,7 +261,7 @@ RCT_EXPORT_MODULE(); if ([response isKindOfClass:UNTextInputNotificationResponse.class]) { [data setValue:[(UNTextInputNotificationResponse *)response userText] forKey:@"_userText"]; } - + NSDictionary *userInfo = @{@"data": data, @"completionHandler": completionHandler}; static dispatch_once_t onceToken; @@ -314,7 +314,7 @@ RCT_EXPORT_MODULE(); -(void) addListener:(NSString *)eventName { [super addListener:eventName]; - + if([eventName isEqualToString:FCMNotificationReceived] && initialNotificationActionResponse) { [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:[initialNotificationActionResponse copy]]; } @@ -358,16 +358,47 @@ RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromi resolve([FIRMessaging messaging].FCMToken); } +RCT_EXPORT_METHOD(getEntityFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +{ + FIROptions *options = FIROptions.defaultOptions; + NSString *entity = options.GCMSenderID; + NSData * deviceToken = [FIRMessaging messaging].APNSToken; + + [[FIRInstanceID instanceID]tokenWithAuthorizedEntity:entity scope:kFIRInstanceIDScopeFirebaseMessaging options:@{@"apns_token": deviceToken} handler:^(NSString * _Nullable token, NSError * _Nullable error) { + + if (error != nil) { + reject([NSString stringWithFormat:@"%ld",error.code],error.localizedDescription,nil); + } else { + resolve(token); + } + }]; +} + +RCT_EXPORT_METHOD(deleteEntityFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +{ + FIROptions *options = FIROptions.defaultOptions;; + NSString *entity = options.GCMSenderID; + + [[FIRInstanceID instanceID]deleteTokenWithAuthorizedEntity:entity scope:kFIRInstanceIDScopeFirebaseMessaging handler:^(NSError * _Nullable error) { + + if (error != nil) { + reject([NSString stringWithFormat:@"%ld",error.code],error.localizedDescription,nil); + } else { + resolve(nil); + } + }]; +} + RCT_EXPORT_METHOD(deleteInstanceId:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - [[FIRInstanceID instanceID]deleteIDWithHandler:^(NSError * _Nullable error) { - - if (error != nil) { - reject([NSString stringWithFormat:@"%ld",error.code],error.localizedDescription,nil); - } else { - resolve(nil); - } - }]; + [[FIRInstanceID instanceID]deleteIDWithHandler:^(NSError * _Nullable error) { + + if (error != nil) { + reject([NSString stringWithFormat:@"%ld",error.code],error.localizedDescription,nil); + } else { + resolve(nil); + } + }]; } - (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken {