ios - Flutter FCM on resume on launch and on message not working in ios 缺少插件实现在启动时触发
问题描述
Flutter FCM on resume on launch and on message not working in ios缺少插件实现dart服务在启动时触发,在android上工作正常以下是用于处理fcm的代码。在IOS中,当应用程序在后台和点击时触发通知应用程序已打开
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print(message);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid =
new AndroidInitializationSettings('launcher_icon');
var initializationSettingsIOS = new IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'123', 'convoy notification', 'convoy notification',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
message['notification']['title'],
message['notification']['body'],
platformChannelSpecifics,
payload: message['data']['payload']);
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
var string = message["data"]["payload"];
var payload = jsonDecode(string);
print(payload);
if (payload != null) {
var type = payload["refresh"];
if (type == "OFFERS") {
Future.delayed(Duration(seconds: 3), () {
_navigateToOffers(payload["id"]);
});
} else if (type == "REQUESTS") {
Future.delayed(Duration(seconds: 3), () {
_navigateToRequests(payload["id"]);
});
}
}
//_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
var string = message["data"]["payload"];
var payload = jsonDecode(string);
print(payload);
if (payload != null) {
var type = payload["refresh"];
if (type == "OFFERS") {
_navigateToOffers(payload["id"]);
} else if (type == "REQUESTS") {
_navigateToRequests(payload["id"]);
}
}
// _navigateToItemDetail(message);
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
解决方案
尝试在 ios/Runner/AppDelegate.swift 中删除这些行:
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }
我遇到了同样的问题,删除此代码后,我的应用程序运行良好。
推荐阅读
- python - Python将csv加载到postgres表列,严格格式
- c# - Azure Function App:在本地调试时发生“冷启动”
- javascript - 根据选择下拉列表中单击的选项更改标记
- java - Vaadin 13 + Spring Boot + Spring Session + Hazelcast。错误:来自客户端的意外消息 ID。预期同步 ID:0,得到 1
- php - 使用 PHP CURL 请求获取验证码图像并返回一些数据
- node.js - 调试节点在 pm2 中崩溃
- php - 在 HTML 页面上显示 IP 地址
- angularjs - 如何在angularjs中将uibmodel对话框文本框值获取到父控制器
- c++ - 如何在 c++ 2d 向量中找到对象(不是 int)的位置?
- python - 使用带有 ffmpeg 的 Popen 时的空行输出