问题:推送通知颤动

时间:2021-06-29 20:04:50

标签: flutter dart push-notification

当用户 B 关注用户 A 时,我尝试向用户 A 发送推送通知(请参阅下面的代码),但由于某些原因它不起作用。我没有收到任何错误,但我认为我的代码有问题。你能告诉我我的代码有什么问题或可以改进的地方吗?谢谢!

home.dart:

@override
  void initState() { 
    super.initState();
    FirebaseMessaging messaging = FirebaseMessaging(); 
    messaging.requestNotificationPermissions(); 
    messaging.configure(); 
    messaging.configure(onMessage: (message) {
      print(message);
      return;
    }, onLaunch: (message) {
      print(message);
      return;
    }, onResume: (message) {
      print(message);
      return;
    });
    messaging.getToken().then((value) => print(value));
  }

函数>index.js:

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

exports.onCreateFollowerNotification = functions.firestore
  .document('/followers/{userId}/userFollowers/{followerId}')
  .onCreate((snapshot, context) => {
    console.log('Notification on Follower Created', snapshot.id);

    const userId = context.params.userId;
    const followerId = context.params.followerId;
    const registrationToken = [userId];

    return admin.messaging().sendToDevice(registrationToken, {notification: {
        title: followerId,
        body: '${followerId} is following you',
      }})
  });

0 个答案:

没有答案