相关疑难解决方法(0)

如何在前台接收推送通知时显示颤动本地通知?

目前,我正在使用警报对话框在应用程序处于前台时接收推送通知时显示通知。但我想在颤振中显示一些非侵入性的东西,比如本地通知。我如何在我的应用程序中实现它?这是我目前的实现:

FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  @override
  void initState() {
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        showDialog(
          context: context,
          builder: (context) => AlertDialog(
            content: ListTile(
              title: Text(message['notification']['title']),
              subtitle: Text(message['notification']['body']),
            ),
            actions: <Widget>[
              FlatButton(
                child: Text('Ok'),
                onPressed: () => Navigator.of(context).pop(),
              ),
            ],
          ),
        );
        print("onMessage: $message");
      },
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
        Navigator.pushNamed(context, '/notify');
      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
      },
    );
}
Run Code Online (Sandbox Code Playgroud)

dart flutter firebase-cloud-messaging

13
推荐指数
1
解决办法
1万
查看次数

Flutter 推送通知仅在应用程序处于后台时才有效

我的问题是关于使用 Flutter 和 firebase_messaging 插件的推送通知

问题:

我已将firebase_messaging插件集成到我的 Flutter 应用程序中以进行推送通知。我可以保证设置是正确的,因为我收到推送通知。仅当我的应用程序在后台运行时才收到推送(例如最小化但在系统内存中可用)时会出现问题。当应用程序在前台或被杀死时,不会收到推送。

为了提供我尝试过的解决方案,我无法弄清楚实际上需要做什么。

我遵循了有关此的教程并应用了每一步来克服该问题,但无济于事。

我正在使用 nodeJS 来处理 firebase-admin 和 serviceaccountkey 文件,因为我需要来自我的数据库的 device_tokens。

节点

 const firebase = require('firebase-admin');
 const serviceAccount = require('../controller/firebase/serviceAccountKey.json');
 firebase.initializeApp({
  credential: firebase.credential.cert(serviceAccount)
 });

 //Function to actually implement the push
 const pushNotificationInitiatorSubscription = (resultValue) => {
 let devicesTokenString = resultValue[0]['device_token'];
 const firebaseToken = devicesTokenString;
 const payLoad = {
   notification: {
   title: 'New Subscription',
   body: 'You have a new subscription to your material ' + resultValue[0]['course_name']
 }
};
const …
Run Code Online (Sandbox Code Playgroud)

push-notification node.js flutter firebase-cloud-messaging

7
推荐指数
1
解决办法
1万
查看次数