// when the app is running, but in the backgroud messaging().onNotificationOpenedApp(remoteMessage => { console.log( '[FCMService] onNotificationOpenedApp Notification caused app to open', ); if (remoteMessage) { const notification = remoteMessage.notification; onOpenNotification(notification); // this.removeDeliveredNotification(notification.notificationId) } });
messaging() .deleteToken() .catch(error => { console.log('[FCMService] delete token error ', error); });
messaging() .requestPermission() .then(() => { this.getToken(onRegister); }) .catch(error => { console.log('[FCMService] request permission rejected ', error); });
messaging().onMessage(async remoteMessage => { console.log('[FCMService] a new FCM message arrived!', remoteMessage); if (remoteMessage) { let notification = null; if (Platform.OS === 'ios') { notification = remoteMessage.data.notification; } else { notification = remoteMessage.notification; } onNotification(notification); } })
const unsubscribe = messaging().onMessage(async remoteMessage => { console.warn("message when app opening...", remoteMessage) }); messaging().onNotificationOpenedApp(remoteMessage => { console.warn( 'app open from background state........:', remoteMessage, .getInitialNotification() .then(remoteMessage => { if (remoteMessage) {
// when the app is opened from a quit state. messaging() .getInitialNotification() .then(remoteMessage => { console.log( '[FCMService] getInitialNotification Notification caused app to open', ); if (remoteMessage) { const notification = remoteMessage.notification; onOpenNotification(notification); // this.removeDeliveredNotification(notification.notificationId) } });
return messaging().onTokenRefresh(token => { console.log('new token', token); }); const authorizationStatus = await messaging().requestPermission(); console.log("authorizationStatus.....", authorizationStatus) if (authorizationStatus) { const deviceRemote = await messaging().registerDeviceForRemoteMessages(); const token = await messaging().getToken(); console.log("fcm token.......", token);
// triggered when have new token messaging().onTokenRefresh(fcmToken => { console.log('[FCMService] new token refresg: ', fcmToken); onRegister(fcmToken); });
messaging() .getToken() .then(fcmToken => { if (fcmToken) { onRegister(fcmToken); messaging().subscribeToTopic('all'); } else { console.log('[FCMService] user does not have a device token'); } }) .catch(error => { console.log('[FCMService] getToken rejected ', error); });
messaging() .hasPermission() .then(enabled => { if (enabled) { // user has permissions this.getToken(onRegister); } else { // user doens't have permission this.requestPermission(onRegister); } }) .catch(error => { console.log('[FCMService] Permission rejected ', error); });
// Register background handler messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('handled in the background when app close and kill...', remoteMessage); });
messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('Message handled in the background!', remoteMessage); });