2017-08-10 79 views
0

我正在使用react-native-push-notification庫推送通知到android。 我從GCM服務器獲取通知。 我得到了函數'onNotification'的作品,當我安慰它時,我在控制檯中看到消息通知。 如何呈現通知並向用戶顯示每個通知(包括按鈕)?我試圖通過狀態或調用函數保存已收到的通知,但它不起作用,似乎不知道外部函數。反應原生渲染推送通知android

這裏是代碼 -

componentDidMount(){ 
 
     PushNotification.configure({ 
 

 
      onNotification: function(notification) { 
 
       console.log('NOTIFICATION:', notification); 
 
      }, 
 
      
 
      senderID: "********", 
 
      popInitialNotification: true, 
 

 

 
     }); 
 
    } 
 

 

 

 
render() { 
 
      return(
 
       <View> 
 
        <Text>Notification</Text> 
 
       </View> 
 

 
      ); 
 

 
     } 
 

 
}

的感謝!

回答

0

對於Android,我會推薦使用FCM(Firebase雲消息傳遞)。另外,包react-native-push-notification對於Android來說很難配置和使用。我會推薦使用react-native-firebase。

我已經發布了關於如何使用FCM and react-native-firebase的教程。

0

如果你想在通知並點擊該按鈕按鈕,運行特定的功能,那麼你應該嘗試

react-native-notifications

它可以讓你對你的用戶在你的應用程序之外,如行動提供額外的功能鈕釦。

enter image description here