почему Firebase Remote Pu sh уведомление не работает в ios, но работает в android - PullRequest
1 голос
/ 20 января 2020

Я установил конфигурацию для получения удаленного уведомления pu sh через response-native-firebase. В android все верно, но в ios я могу получить FCMToken, но не могу получить pop up pu sh уведомление. podFile:

 pod 'Firebase/Core'
 pod 'Firebase/Auth'
 pod 'Firebase/Messaging'
 pod 'GoogleIDFASupport'

мой AppDelegate.m:

    #import <Firebase.h>
    #import "RNFirebaseNotifications.h"
    #import "RNFirebaseMessaging.h"
    ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [RNFirebaseNotifications configure];
...
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
  [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}

и мой код для получения токена FCm и шоу:

componentDidMount() {
    const channel = new firebase.notifications.Android.Channel(
      'insider',
      'insider channel',
      firebase.notifications.Android.Importance.Max,
    );
    firebase.notifications().android.createChannel(channel);
    this.checkPermission();
    this.createNotificationListeners();
  }

  async getToken() {
    let tokenFCM = await AsyncStorage.getItem('tokenFCM');
    console.log(tokenFCM);

    if (!tokenFCM) {
      // console.log('token not find');
      try {
        tokenFCM = await firebase.messaging().getToken();
        if (tokenFCM) {
          await AsyncStorage.setItem('tokenFCM', tokenFCM);
          // do sth here
        }
      } catch {
         console.log('token not find2');

      }
    } else {
      // console.log('token is find');
    }
  }

  async checkPermission() {
    const enabled = await firebase.messaging().hasPermission();
    if (enabled) {
      this.getToken();
    } else {
      this.requestPermission();
    }
  }

  async requestPermission() {
    try {
      await firebase.messaging().requestPermission();
      this.getToken();
    } catch (error) {
      await AsyncStorage.setItem('tokenFCM', '');
      console.log('permission rejected');
    }
  }

  createNotificationListeners() {
    firebase.notifications().onNotification(notification => {
      notification.android.setChannelId('insider').setSound('default');
      notification.android.setSmallIcon('@mipmap/...');
      firebase.notifications().displayNotification(notification);
    });
  }

почему я могу см. уведомление о sh в Android, но не отображение в ios?

1 Ответ

0 голосов
/ 21 января 2020

Я решил это, добавив act-native-permissions .

import {requestNotifications} from 'react-native-permissions';

и при проверке разрешений сделайте это,

await requestNotifications(['alert', 'badge', 'sound']);

Вы начнете получать уведомления pu sh

Надеюсь, это поможет. Чувствовать . бесплатно для сомнений

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...