简体   繁体   English

我可以将 flutter 资产用于 iOS 上的本地通知附件吗

[英]Can I use flutter assets for local notification attachments on iOS

I am using the flutter_local_notifications package to show notifications in my flutter app.我正在使用 flutter_local_notifications package 在我的 flutter 应用程序中显示通知。 I would like to show an image with my notifications on iOS by adding the image to the "attachments" array in IOSNotificationDetails.我想通过将图像添加到 IOSNotificationDetails 中的“附件”数组中,在 iOS 上显示带有通知的图像。

final iosNotificationDetails = IOSNotificationDetails(
    attachments: [IOSNotificationAttachment('assets/image.png')],
);

I have seen the example to download the image from a URL and save it in the application documents directory, but would like to know if there is a way to either load an image directly from the flutter assets or from a file in my iOS project.我已经看到了从 URL 下载图像并将其保存在应用程序文档目录中的示例,但想知道是否有一种方法可以直接从 flutter 资产或从我的 Z1BBZDF605991920DB11CBDF8508 项目中的文件加载图像。

import 'dart:async';导入“飞镖:异步”; import 'dart:io';导入“飞镖:io”;

import 'package:flutter/services.dart' show rootBundle;导入 'package:flutter/services.dart' 显示 rootBundle; import 'package:path_provider/path_provider.dart';导入'包:path_provider/path_provider.dart';

Future getImageFileFromAssets(String path) async { final byteData = await rootBundle.load('assets/$path'); Future getImageFileFromAssets(String path) async { final byteData = await rootBundle.load('assets/$path');

final file = File('${(await getTemporaryDirectory()).path}/$path');最终文件 = File('${(await getTemporaryDirectory()).path}/$path'); await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));等待 file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

return file;返回文件; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ios中一起使用本地通知和推送通知? - can I use local notification and push notification together in ios? 如何在 flutter 后台收到本地通知时调用 function - How can I call a function on local notification received in background in flutter Flutter 本地通知在 IOS 上未按预期工作 - Flutter local notification is not working as expected on IOS 我应该使用推送还是可以使用本地通知? - Should I use push or can I use local notification? 如何获得firemonkey在iOS上显示本地通知? - How can I get firemonkey to display a local notification on iOS? 我可以从后台取消iOS本地通知吗? - Can I cancel iOS local notification from the background? 为什么在Swift 3上无法从iOS上的本地收到通知? - Why I can not get notification from local on iOS with swift 3? 如何使用UISwitch打开本地通知? - How can i use UISwitch to turn of local notification? 将Firebase通知与本地通知一起使用iOS - Use firebase notification with local notifications iOS 我可以下载音频文件并将其用于iOS中的推送通知声音吗? - Can I download an audio file and use it for push notification sound in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM