gpt4 book ai didi

ios - 如何在 iOS 上使用 Firebase 和 Flutter 获取推送通知?

转载 作者:IT王子 更新时间:2023-10-29 06:33:23 29 4
gpt4 key购买 nike

我尝试了许多不同的教程,例如这个https://medium.com/flutterpub/enabling-firebase-cloud-messaging-push-notifications-with-flutter-39b08f2ed723

但是我无法在我的 iPhone 上接收任何推送通知。它在 Android 上完美运行。

我使用 firebase_messaging:^4.0.0+4 和 flutter_local_notifications:^0.6.1

问题是尽管使用 getToken() 收到 token ,但在 iOS 中没有调用任何监听器(onMessage、onResume 或 onLaunch)

没有错误信息。我找不到这种行为的原因。如果有人能帮助我,我会很高兴。

谢谢。

_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("IM HERE ON MESSAGE");
print('on message $message');


String message_as_String = json.encode(message);
print(message_as_String);
String title = "test";
String body = "test";
String screen = "test";


var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
playSound: false, importance: Importance.Max, priority: Priority.High);
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails(presentSound: false);
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
body,
title,
platformChannelSpecifics,
payload: screen,
);
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
String screen = message["screen"];

},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token){
print(token);
});
}

最佳答案

flutter_local_notifications 的文档说明如下:

NOTE: this plugin registers itself as the delegate to handle incoming notifications and actions. This may cause problems if you're using other plugins for push notifications (e.g. firebase_messaging) as they will most likely do the same and it's only possible to register a single delegate.

几个问题:

  • 为什么要同时使用这两个包?
  • 您是否在 Xcode 中的 Target 下的 Background Modes 中启用了Remote notifications
  • 您是否为 iOS 上的通知创建了证书? (APNS:苹果推送通知服务(link)

让我知道你的结果如何 :)

关于ios - 如何在 iOS 上使用 Firebase 和 Flutter 获取推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56027111/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com