【问题标题】:How to save the downloaded file on "on my iphone" folder?如何将下载的文件保存在“我的 iPhone”文件夹中?
【发布时间】:2022-01-14 08:11:31
【问题描述】:

简而言之,我正在尝试下载一个 pdf 文件并将其保存在“我的 iphone”文件夹中。

 Future<File?> createFile() async {
   String attachment = "attachments";
   Directory dir;
   File? attachmentPath;
   if (Platform.isAndroid) {
    if (await _requestPermission(Permission.storage)) {
    dir = (await getExternalStorageDirectory())!;
    attachmentPath =
        File('${dir.parent.path}/$attachment/${getFileName()}');

    }
   } else if (Platform.isIOS) {
  if (await _requestPermission(Permission.storage)) {
    dir = (await getApplicationDocumentsDirectory());
    attachmentPath =
        File('${dir.path}/$attachment/${getFileName()}');
  }
}
if (!await attachmentPath!.exists()) {
  await attachmentPath.create(recursive: true);
}
return attachmentPath;
}


Future<bool> _requestPermission(Permission permission) async {
print(await permission.isGranted);
if (await permission.isGranted) {
  return true;
} else {
  var result = await permission.request();
  if (result == PermissionStatus.granted) {
    return true;
 }
  }
 return false;
}

我还在 \ios\Runner\Info.plist 中启用了 LSSupportsOpeningDocumentsInPlace 和 UIFileSharingEnabled,但我在“我的 iphone 上”中找不到应用程序文件夹 &lt;key&gt;UIFileSharingEnabled&lt;/key&gt; &lt;true/&gt; &lt;key&gt;LSSupportsOpeningDocumentsInPlace&lt;/key&gt; &lt;true/&gt;

【问题讨论】:

    标签: ios flutter flutter-ios


    【解决方案1】:

    iOS 应用程序是沙盒。下载到沙箱中(例如 Documents 文件夹)。

    您无法直接访问“我的 iPhone”文件夹。 Apple 会(例如,Safari 下载会保存到该文件夹​​),但您不会。 用户可以将下载的 PDF 移动到“在我的 iPhone 上”(通过 UIDocumentPickerViewController),但您不能自行执行移动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多