Skip to content

Commit

Permalink
Add registerForRemoteNotifications method
Browse files Browse the repository at this point in the history
  • Loading branch information
timwangdev committed Oct 23, 2018
1 parent 137fe59 commit 096e50e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions ios/RNFirebase/messaging/RNFirebaseMessaging.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,11 @@ declare module 'react-native-firebase' {
*/
hasPermission(): Promise<boolean>;

/**
* Register for iOS remote notifications
*/
registerForRemoteNotifications(): Promise<void>;

/**
* Send an upstream message
*/
Expand Down
4 changes: 4 additions & 0 deletions src/modules/messaging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export default class Messaging extends ModuleBase {
return getNativeModule(this).hasPermission();
}

registerForRemoteNotifications(): Promise<void> {
return getNativeModule(this).registerForRemoteNotifications();
}

sendMessage(remoteMessage: RemoteMessage): Promise<void> {
if (!(remoteMessage instanceof RemoteMessage)) {
return Promise.reject(
Expand Down

0 comments on commit 096e50e

Please sign in to comment.