open_file icon indicating copy to clipboard operation
open_file copied to clipboard

ios and flutter mixing, Open file error

Open unti1you opened this issue 1 year ago • 9 comments

[ERROR] failed to get service endpoint creating for for item at URL file:///var/mobile/Containers/Data/Application/1415D775-BCFC-486C-88C2-82F4A107E404/Documents/%E4%B8%AD%E4%BA%A4%E6%95%B0%E7%A7%91%E7%AE%A1%E7%90%86%E5%90%8E%E5%8F%B0ios%E9%A1%B5%E9%9D%A2%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3.docx: Error Domain=NSCocoaErrorDomain Code=3328 "所请求的操作未能完成,因为该功能不受支持。" Collaboration: error loading metadata for documentURL:file:///var/mobile/Containers/Data/Application/1415D775-BCFC-486C-88C2-82F4A107E404/Documents/%E4%B8%AD%E4%BA%A4%E6%95%B0%E7%A7%91%E7%AE%A1%E7%90%86%E5%90%8E%E5%8F%B0ios%E9%A1%B5%E9%9D%A2%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3.docx error:Error Domain=NSCocoaErrorDomain Code=3328 "所请求的操作未能完成,因为该功能不受支持。" Attempt to present <UIActivityViewController: 0x105298600> on <WKMainTabbarController: 0x1038d8fc0> (from <WKMainTabbarController: 0x1038d8fc0>) whose view is not in the window hierarchy. connection invalidated

unti1you avatar Jan 13 '25 09:01 unti1you

The Flutter module can successfully open files when run separately

unti1you avatar Jan 13 '25 09:01 unti1you

OpenFilePlugin.m

  • (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {},

In this methon,[self openFileWithUIActivityViewController:fileURL]; fileURL has a value;

  • (void)openFileWithUIActivityViewController:(NSURL )fileURL{}, Jump to this method, fileURL becomes to be a (NSURL)0x0

unti1you avatar Jan 13 '25 10:01 unti1you

NSURL *fileURL = [NSURL fileURLWithPath:filePath]; There is Chinese in the file path,

unti1you avatar Jan 13 '25 10:01 unti1you

error log : Invalid content type identifier com.apple.pktransaction specified in extension com.apple.Passbook.QuicklookPreviewExtension

unti1you avatar Jan 13 '25 11:01 unti1you

To get the real path of the file, it is recommended to use path_provider to get it, and then determine whether the app has permission to open it

crazecoder avatar Jan 13 '25 15:01 crazecoder

// 下载缓存并预览文件 Future downloadAndPreviewFile(String? url, String? fileName) async { if (url == null || fileName == null) { MyToast.showToast("下载地址为空"); } else { try { // 获取设备存储路径 final directory = DeviceUtils.isAndroid ? await getExternalStorageDirectory() : await getApplicationDocumentsDirectory(); final filePath = '${directory?.path}/$fileName'; // 文件保存路径 // 检查文件是否已经存在 final file = File(filePath);

    if (await file.exists()) {
      // 直接打开文件预览
      Log.d('文件已下载,已经存在');
      // 打开文件预览
      final extension = path.extension(filePath).toLowerCase();
      final mimeType = types[extension] ?? 'public.data';
      await OpenFile.open(filePath, type: mimeType);
      return;
    }
    // 使用 dio 下载文件
    late Dio dio = Dio();
    MyDialog.showLoading();

    await dio.download(
      url,
      filePath,
      onReceiveProgress: (received, total) {
        Log.d('received: $received');
        Log.d('total: $total');
      },
    );
    Log.d('Download complete!');
    MyDialog.dismiss();

    // 打开文件预览
    final extension = path.extension(filePath).toLowerCase();
    final mimeType = types[extension] ?? 'public.data';
    await OpenFile.open(filePath, type: mimeType);
  } catch (e) {
    MyDialog.dismiss();
    MyToast.showToast('文件下载失败');
    // 捕获异常并打印日志
      Log.d('Dio error: $e');
  } finally {
    Log.d('Download end!');
    MyDialog.dismiss();
  }
}

} } types is IOS with UTI (DocumentInteraction Auto) Successfully preview files on Android and iPhone emulators, but report the above error when iOS and Flutter are mixed on iPhone

unti1you avatar Jan 14 '25 01:01 unti1you

error log : Invalid content type identifier com.apple.pktransaction specified in extension com.apple.Passbook.QuicklookPreviewExtension

I'm not experienced mixed with the situation, but I found the same problem on here, said it may be just a warning

crazecoder avatar Jan 14 '25 03:01 crazecoder

error log : Invalid content type identifier com.apple.pktransaction specified in extension com.apple.Passbook.QuicklookPreviewExtension

I'm not experienced mixed with the situation, but I found the same problem on here, said it may be just a warning

I have already sent channelMethod using mixed encoding and processed it using iOS native, temporarily resolving this issue

unti1you avatar Jan 14 '25 03:01 unti1you

error log : Invalid content type identifier com.apple.pktransaction specified in extension com.apple.Passbook.QuicklookPreviewExtension

I'm not experienced mixed with the situation, but I found the same problem on here, said it may be just a warning

Anyway, thank you very much

unti1you avatar Jan 14 '25 03:01 unti1you