Commit 75bd35dd authored by Libin Lu's avatar Libin Lu Committed by GitHub

Merge pull request #467 from riyaz942/master

Delete instanceId function
parents 6baaf814 84296f5d
......@@ -372,6 +372,15 @@ class App extends Component {
my_custom_data_1: 'my_custom_field_value_1',
my_custom_data_2: 'my_custom_field_value_2'
});
FCM.deleteInstanceId()
.then( () => {
//Deleted instance id successfully
//This will reset Instance ID and revokes all tokens.
})
.catch(error => {
//Error while deleting instance id
});
}
}
```
......
......@@ -27,7 +27,7 @@ import android.os.Bundle;
import android.util.Log;
import android.content.Context;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
......@@ -74,6 +74,17 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
promise.resolve(FirebaseInstanceId.getInstance().getToken());
}
@ReactMethod
public void deleteInstanceId(Promise promise){
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
promise.resolve(null);
} catch (IOException e) {
e.printStackTrace();
promise.reject(null,e.getMessage());
}
}
@ReactMethod
public void presentLocalNotification(ReadableMap details) {
Bundle bundle = Arguments.toBundle(details);
......
......@@ -48,6 +48,10 @@ FCM.getFCMToken = () => {
return RNFIRMessaging.getFCMToken();
};
FCM.deleteInstanceId = () =>{
return RNFIRMessaging.deleteInstanceId();
};
FCM.getAPNSToken = () => {
if (Platform.OS === 'ios') {
return RNFIRMessaging.getAPNSToken();
......
......@@ -3,7 +3,7 @@
#import <FirebaseCore/FIRApp.h>
#import <FirebaseMessaging/FirebaseMessaging.h>
#import <FirebaseInstanceID/FirebaseInstanceID.h>
#import <React/RCTEventEmitter.h>
@import UserNotifications;
......
......@@ -231,6 +231,18 @@ RCT_EXPORT_METHOD(getFCMToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromi
resolve([FIRMessaging messaging].FCMToken);
}
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);
}
}];
}
- (void)messaging:(nonnull FIRMessaging *)messaging didRefreshRegistrationToken:(nonnull NSString *)fcmToken {
[self sendEventWithName:FCMTokenRefreshed body:fcmToken];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment