diff --git a/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java b/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java index 42a32d1e62..f2bf1df3ed 100644 --- a/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java +++ b/android/src/main/java/io/invertase/firebase/messaging/RNFirebaseMessaging.java @@ -64,6 +64,11 @@ public void requestPermission(Promise promise) { promise.resolve(null); } + @ReactMethod + public void registerForRemoteNotifications(Promise promise) { + promise.resolve(null); + } + // Non Web SDK methods @ReactMethod public void hasPermission(Promise promise) { diff --git a/ios/RNFirebase/messaging/RNFirebaseMessaging.m b/ios/RNFirebase/messaging/RNFirebaseMessaging.m index 92978cafab..7905afbe2f 100644 --- a/ios/RNFirebase/messaging/RNFirebaseMessaging.m +++ b/ios/RNFirebase/messaging/RNFirebaseMessaging.m @@ -124,9 +124,6 @@ - (void)messaging:(nonnull FIRMessaging *)messaging } }]; } - dispatch_async(dispatch_get_main_queue(), ^{ - [RCTSharedApplication() registerForRemoteNotifications]; - }); } RCT_EXPORT_METHOD(requestPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { @@ -159,6 +156,11 @@ - (void)messaging:(nonnull FIRMessaging *)messaging } } +RCT_EXPORT_METHOD(registerForRemoteNotifications:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { + [RCTSharedApplication() registerForRemoteNotifications]; + resolve(nil); +} + // Non Web SDK methods RCT_EXPORT_METHOD(hasPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { diff --git a/src/index.d.ts b/src/index.d.ts index eee0f45d88..13b76e81b3 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1205,6 +1205,11 @@ declare module 'react-native-firebase' { */ hasPermission(): Promise; + /** + * Register for iOS remote notifications + */ + registerForRemoteNotifications(): Promise; + /** * Send an upstream message */ diff --git a/src/modules/messaging/index.js b/src/modules/messaging/index.js index ccafeee6b0..db7156c5f8 100644 --- a/src/modules/messaging/index.js +++ b/src/modules/messaging/index.js @@ -137,6 +137,10 @@ export default class Messaging extends ModuleBase { return getNativeModule(this).hasPermission(); } + registerForRemoteNotifications(): Promise { + return getNativeModule(this).registerForRemoteNotifications(); + } + sendMessage(remoteMessage: RemoteMessage): Promise { if (!(remoteMessage instanceof RemoteMessage)) { return Promise.reject(