【发布时间】:2019-09-25 09:11:14
【问题描述】:
我尝试了许多不同的教程,例如这个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() 接收到令牌,但在 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);
});
}
【问题讨论】:
-
更新:我发现当应用程序在 TestFlight onMessage 时被调用。所以只有当应用程序在前台时。此外,当应用程序在后台并且我发送一条消息(我没有收到推送通知!)但是当我进入应用程序状态时,我写了一条信息消息“在重新启动时被调用”。
-
看看我的帖子,可能对你有帮助stackoverflow.com/questions/56507900/…
-
@ExtUser1 你解决了后台推送通知的问题吗?
标签: ios firebase flutter firebase-cloud-messaging apple-push-notifications