Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

@react-native-firebase/messaging not getting device token in real ios device

$
0
0

I am using react-native-firebase v8 and react-native v0.61.2. I have recently upgraded my react-native version from 0.61 to 0.61.2. In android everything works perfect but in ios real device messaging.getToken() throw error in catch block, not getting any token.

Error:

enter image description here

my FCM-service file

class FcmService {register = (onRegister,onNotification, onOpenNotification) =>{    this.checkPermission(onRegister)    // when register function call that time we create notification listener    this.createNoitificationListeners(onRegister, onNotification, onOpenNotification)}registerAppWithFCM = async () => {    if(Platform.OS === 'ios') {        await messaging().registerDeviceForRemoteMessages();        await messaging().setAutoInitEnabled(true);    }}checkPermission = (onRegister) => {    messaging().hasPermission()        .then(enabled  => {            if (enabled) {                Alert.alert('enabled')                //user has permission                this.getToken(onRegister)            } else {                //user don't have permission                this.requestPermission(onRegister)            }        }).catch(error => {            let err = `check permission error${error}`            Alert.alert(err)        // console.log("[FCMService] Permission rejected", error)    })}getToken = async (onRegister) => {    let fcmToken = await AsyncStorage.getItem(Constants.FCM_TOKEN);    if(!fcmToken) {        messaging().getToken()        .then(fcmToken => {            Alert.alert(fcmToken)            if (fcmToken) {                onRegister(fcmToken)            } else {                // console.log("[FCMService] User does not have a device token")            }        }).catch(error => {            let err = `FCm token get error${error}`            Alert.alert(err)        // console.log("[FCMService] getToken rejected ", error)    })    }    else {    }}requestPermission = (onRegister) => {    messaging().requestPermission().then(() => {        this.getToken(onRegister)    }).catch(error => {        // console.log("[FCMService] Requested persmission rejected ", error)    })}deletedToken = async () => {    await messaging().deleteToken()        .catch(error => {            // console.log("Delected token error ", error)        })}createNoitificationListeners = (onRegister, onNotification, onOpenNotification) => {    messaging().onNotificationOpenedApp(remoteMessage => {        Alert.alert(remoteMessage)        // console.log("[FCMService] onNotificationOpenedApp Notification caused app to open from background state:", remoteMessage);        if(remoteMessage) {            onOpenNotification(remoteMessage)        }    });    // when the application is opened form a quit state    messaging()        .getInitialNotification()        .then(remoteMessage => {            Alert.alert(remoteMessage)            // console.log('[FCMService] getInitialNotification Notification caused app to open from quit state:', remoteMessage);            if (remoteMessage) {                onOpenNotification(remoteMessage)            }        }    );    // Foreground state messages    this.messageListener = messaging().onMessage(async remoteMessage => {        Alert.alert(remoteMessage)         //console.log("[FCMService] A new FCM message arrived", remoteMessage);        if(remoteMessage) {            let notification = null;            if(Platform.OS === 'ios') {                notification = remoteMessage            } else {                notification = remoteMessage            }            onNotification(notification);        }    });    // Triggered when have new token    messaging().onTokenRefresh(fcmToken => {        // console.log("New token refresh: ", fcmToken)        onRegister(fcmToken)    })}unRegister = () => {    this.messageListener()}

}

in App.js file i called that method

fcmService.registerAppWithFCM();fcmService.register(this.onRegister, this.onNotification, this.onOpenNotification);

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>