iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 17
1
## 今天我們要使用Firebase functions  推送 FCM 給昨天我們寫好的 APP 

https://ithelp.ithome.com.tw/upload/images/20191003/20104220n6OS6c0xPX.png

https://ithelp.ithome.com.tw/upload/images/20191003/20104220AvNAwRdO84.png

https://ithelp.ithome.com.tw/upload/images/20191003/20104220GDBNETbaNt.png

https://ithelp.ithome.com.tw/upload/images/20191003/20104220tp2NtlsLCG.png

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

/////is ok
exports.helloFCM = functions.region('asia-northeast1').https.onRequest(async (request, response) => {
  console.log('A new user signed in for the first time.');
  const fullName = 'Anonymous';
  const Ipad_token = "cTBvQaDOt1A:APAXXXXXXXX5U6K1zhNfw4FkKJ";

  var registrationToken = 'YOUR_REGISTRATION_TOKEN';
  var topic = 'highScores';
  var message = {
    data: {
      score: '850',
      time: '2:45'
    },
    notification: {
      title: "FCM D 加辣",
      body: "FCM D 加辣",
    },

    token: Ipad_token
  };
  

  await admin.messaging().send(message).then((response) => {
    console.log('Successfully sent message:', response);
    return null;

  })
   admin.messaging().send(message).then((response) => {
    console.log('Successfully sent message:', response);
    return null;

  })
    .catch((error) => {
      console.log('Error sending message:', error);
    });


上一篇
[Day16] 與 Firebase 結合之 F.C.M. (媽~我終於搞定 FCM 了)
下一篇
[DAY18]先告一段落的RN好用套件推薦,Fluttre結合Firebase開始
系列文
小孩子才做選擇 ! Flutter & React Native 我全都要32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言