Merge pull request #443 from bm-software/master
deleteInstanceId feature to unregister from push notifications until next getToken call.
This commit is contained in:
commit
b2987b7362
|
@ -27,6 +27,7 @@ import com.google.firebase.messaging.RemoteMessage.Notification;
|
|||
|
||||
import io.invertase.firebase.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -72,6 +73,18 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule implements L
|
|||
promise.resolve(FirebaseInstanceId.getInstance().getToken());
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void deleteInstanceId(Promise promise){
|
||||
try {
|
||||
Log.d(TAG, "Deleting instance id");
|
||||
FirebaseInstanceId.getInstance().deleteInstanceId();
|
||||
promise.resolve(null);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
promise.reject(null, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void createLocalNotification(ReadableMap details) {
|
||||
Bundle bundle = Arguments.toBundle(details);
|
||||
|
|
|
@ -608,6 +608,10 @@ declare module "react-native-firebase" {
|
|||
* This token can be used in the Firebase console to send messages to directly.
|
||||
*/
|
||||
getToken(forceRefresh?: Boolean): Promise<string>
|
||||
/**
|
||||
* Reset Instance ID and revokes all tokens.
|
||||
*/
|
||||
deleteInstanceId(): Promise<any>
|
||||
/**
|
||||
* On the event a devices FCM token is refreshed by Google,
|
||||
* the new token is returned in a callback listener.
|
||||
|
|
|
@ -257,6 +257,16 @@ RCT_EXPORT_METHOD(getToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
|
|||
resolve([FIRMessaging messaging].FCMToken);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(deleteInstanceId:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
[FIRInstanceID instanceID] deleteIDWithHandler:^(NSError * _Nullable error) {
|
||||
if (!error) {
|
||||
resolve(nil);
|
||||
} else {
|
||||
reject(@"instance_id_error", @"Failed to delete instance id", error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
if (RCTRunningInAppExtension()) {
|
||||
return;
|
||||
|
|
|
@ -109,6 +109,14 @@ export default class Messaging extends ModuleBase {
|
|||
return this._native.getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Instance ID and revokes all tokens.
|
||||
* @returns {*|Promise.<*>}
|
||||
*/
|
||||
deleteInstanceId() {
|
||||
return this._native.deleteInstanceId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and display a local notification
|
||||
* @param notification
|
||||
|
|
Loading…
Reference in New Issue