iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 18
1
自我挑戰組

I Shot You 不小心系列 第 18

React Native Notification - IOS

  • 分享至 

  • xImage
  •  

IOS

Initial React Native App

  $ react-native init rn_notification

Install

  $ yarn add @react-native-firebase/app @react-native-firebase/messaging
  $ cd ios && pod install && cd ..

Firebase

Download GoogleService-Info.plist

podFile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

$FirebaseSDKVersion = '6.29.0'
... other settings

AppDelegate.m

...import
#import <Firebase.h>
... others settings

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

Image

Demo

Image

Next - Android push notification

參考資訊

react-native-permissions

issue

issue2

firebase


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

尚未有邦友留言

立即登入留言