iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 19
1
自我挑戰組

I Shot You 不小心系列 第 19

React-Native-Notification-Android

  • 分享至 

  • xImage
  •  

Android

Initial React Native App

  $ react-native init rn_notification

Install

  $ yarn add @react-native-firebase/app @react-native-firebase/messaging

Firebase

Download GoogleService-Info.plist

configure Android

index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

async function requestUserPermission() {
  try {
    const messageinstance = messaging();
    const authStatus = await messageinstance.requestPermission();
    const enabled =
      authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
      authStatus === messaging.AuthorizationStatus.PROVISIONAL;
  
    if (enabled) {
      await messageinstance.registerDeviceForRemoteMessages();
      const token = await messageinstance.getToken();
      console.log('token:', token);
    }
  } catch(error) {
  console.log("requestUserPermission -> error", error)
  }
}

requestUserPermission();
AppRegistry.registerComponent(appName, () => App);

APNS Service

wiki Apns Service

Next - Android push notification

參考資訊

react-native-permissions

issue

issue2

firebase


上一篇
React Native Notification - IOS
下一篇
Express - Router
系列文
I Shot You 不小心30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言