2

I'm using this library.は、私は通知に表示するためにプッシュ通知を取得しようとしてる

は私のネクサス5(アンドロイド6.0.1)でトレイ反応するネイティブ-FCMとのネイティブプッシュ通知に反応します。 React Native 0.42を使用する、React Native CLI 2.0.1。私はUbuntu 14.04で開発しています。

私はfirebaseを使用しています。私は私のコンソール>通知>メッセージを送る>特定のデバイス(私は以下のリモートデバッグconsole.logから取得)に行きます。

コードで見られるように通知をログに記録していますが、それらはログに表示されるため、デバイスに送信されます。

しかし、通知トレイに表示する方法はわかりません。ドキュメントやフォーラムを検索すると、デフォルトで表示されるはずです。

componentDidMount() { 
     FCM.requestPermissions(); // for iOS 
     FCM.getFCMToken().then(token => { 
      console.log(token) 
      // store fcm token in your server 
     }); 
     this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => { 
      console.log(notif) 

     }); 
}); 
+0

は...あなたはこれを任意の解決策を持っていました? – Anu

+0

FCM.presentLocalNotification()を使用する必要があります。あなたのアプリがアクティブな場合、通知の処理はあなたの上にあるのに対して、それが非アクティブの場合、それはそれを表示する電話ですauto – MaieonBrix

答えて

0

トップトレイに通知を表示するには、「custom_notification」が必要なようです。

"custom_notification":{ "ボディ": "試験体"、 "タイトル": "テストタイトル"、 "色": "#00ACD4"、 "優先順位" 私は私のペイロードにこれを追加しました: "アイコン"、 "高": "ic_notif"、 "グループ": "GROUP"、 "ID": "ID"、 "show_in_foreground":だから真 }

、私はアプリを考えます通知を受け取り、データを解析し、このcustom_notificationパラメータを追加する必要があります。どのようにあなたのコンストラクタで、次の程度

0

:私は同じ問題を抱えてい

FCM.requestPermissions(); // for iOS 
FCM.getFCMToken().then(token => { 
    console.log(token) 
    // store fcm token in your server 
}); 

this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => { 
    // do some component related stuff 
    console.log(notif); 
    //alert(notif.fcm.body); 

    FCM.presentLocalNotification({ 
    id: "UNIQ_ID_STRING",        // (optional for instant notification) 
    title: "My Notification Title",      // as FCM payload 
    body: notif.fcm.body,     // as FCM payload (required) 
    sound: "default",         // as FCM payload 
    priority: "high",         // as FCM payload 
    click_action: "ACTION",        // as FCM payload 
    badge: 10,           // as FCM payload IOS only, set 0 to clear badges 
    number: 10,           // Android only 
    ticker: "My Notification Ticker",     // Android only 
    auto_cancel: true,         // Android only (default true) 
    large_icon: "ic_launcher",       // Android only 
    icon: "ic_launcher",        // as FCM payload, you can relace this with custom icon you put in mipmap 
    big_text: "Show when notification is expanded",  // Android only 
    sub_text: "This is a subText",      // Android only 
    color: "red",          // Android only 
    vibrate: 300,          // Android only default: 300, no vibration if you pass null 
    tag: 'some_tag',         // Android only 
    group: "group",          // Android only 
    picture: "https://google.png",      // Android only bigPicture style 
    ongoing: true,          // Android only 
    my_custom_data: 'my_custom_field_value',    // extra data you want to throw 
    lights: true,          // Android only, LED blinking (default false) 
    show_in_foreground: true         // notification when app is in foreground (local & remote) 
    }); 
}); 

FCM.subscribeToTopic('test_topic'); 
関連する問題