اذهب إلى المحتوى

السؤال

نشر

 

الاشعارات لاتعمل والهذه الميثود  

    // When the application is running, but in the background
    messaging().onNotificationOpenedApp(remoteMessage => {
      console.log(
        '[FCMService] onNotificationOpenedApp Notification caused app to open from background state:',
        remoteMessage,
      );
      
      // يظهر فى الكونسول 
      //  onNotificationOpenedApp Notification caused app to open from background state: null
      // null اعتقد ان المشكلة تكمن فى 
      

 

 

هذا هو الكود بالكامل ..


  createNotificationListeners = (
    onRegister: (arg0: string) => void,
    onNotification: (
      arg0: FirebaseMessagingTypes.Notification | undefined,
      arg1: {[key: string]: string} | undefined,
    ) => void,
    onOpenNotification: (
      arg0: FirebaseMessagingTypes.Notification | undefined,
      arg1: {[key: string]: string} | undefined,
    ) => void,
  ) => {
    // When the application is running, but in the background
    messaging().onNotificationOpenedApp(remoteMessage => {
      
      // null هنا المشكلة حيث انه يطبع فى الكونسول 
      
      console.log(
        '[FCMService] onNotificationOpenedApp Notification caused app to open from background state:',
        remoteMessage,
      );
      if (remoteMessage) {
        const notification = remoteMessage.notification;
        onOpenNotification(notification, remoteMessage.data);
      }
    });

    // When the application is opened from a quit state.
    messaging()
      .getInitialNotification()
      .then(remoteMessage => {
        console.log(
          '[FCMService] getInitialNotification Notification caused app to open from quit state:',
          remoteMessage,
        );

        if (remoteMessage) {
          const notification = remoteMessage.notification;
          onOpenNotification(notification, remoteMessage.data);
        }
      });

    // Foreground state messages
    this.messageListener = messaging().onMessage(async remoteMessage => {
      console.log('[FCMService] A new FCM message arrived!', remoteMessage);
      if (remoteMessage) {
        let notification = null;
        if (Platform.OS === 'ios') {
          notification = remoteMessage.notification;
        } else {
          notification = remoteMessage.notification;
        }
        onNotification(notification, remoteMessage.data);
      }
    });

    // Triggered when have new token
    messaging().onTokenRefresh(fcmToken => {
      console.log('[FCMService] New token refresh: ', fcmToken);
      onRegister(fcmToken);
    });
  };

 

Recommended Posts

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...