抖动图像通知不能在后台工作&终止。它在前台正常工作。下载一个图像并保存临时目录(Directory.systemTemp),然后获取一个在前台显示图像的路径
`if (Platform.isIOS) {
if (message.data['image'] != null) {
url = message.data['image'];
var formatname = url.toString().split(".");
var length = formatname.length - 1;
var format = formatname[length];
log("message$format");
var formatlist = ['jpg', 'gif', 'png'];
bigpicture = await DownloadUtil.downloadfiles(url,
"bigpicture.${(format.isEmpty || formatlist.contains(format)) ? format : "jpg"}");
print(bigpicture);
} else {
bigpicture = " ";
}
}
}`
flutter本地通知插件版本(flutter_local_notifications:^9.2.0). firebase消息传递包版本(firebase消息传递:^11.2.5).
`flutterLocalNotificationsPlugin.show(
id,
message.data["title"],
message.data["body"],
NotificationDetails(
iOS: ios != null
? IOSNotificationDetails(
attachments: message.data['image'] != null
? <IOSNotificationAttachment>[
IOSNotificationAttachment(bigpicture),
]
: <IOSNotificationAttachment>[],
)
: null,
),
payload: json.encode(message.data));`
有效载荷:-
`{
"message": {
"notification": {
"title": "Welcome message",
"body": "Firebase Nodification Success",
"sound": "Default",
"imageUrl": "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg"
},
"data": {
"title": "Welcome message12",
"body": "Firebase Nodification Success🙂",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"image": "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg",
"status": "Received"
}
},
"registrationToken": "**fcmtoken**"
}`
Flutter医生:-
`Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.5.1 21G83 darwin-arm, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.69.2)
[✓] Connected device (2 available
[✓] HTTP Host Availability
• No issues found!`
1条答案
按热度按时间4uqofj5v1#
payload:-
创建通知服务扩展
成功创建iOS应用程序后,您需要创建通知服务扩展。以下是如何创建通知服务扩展的步骤。
1.在Xcode菜单中,转到File > New > Target。
1.选择Notification Service Extension。
1.给出扩展服务的名称并单击完成按钮。
根据您的意愿键入产品名称(例如:-ImageNotificationService)
您在xcode中添加了firebase Messaging包(此行是在您的包中安装firebase messaging)(target 'this your notification service contact name')
此Info.plist在imagenotificationservice文件夹plist中
此行为notificationservice.swift
如果您有任何疑问,请在下面评论:-