Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios and flutter mixing, Open file error #322

Open
unti1you opened this issue Jan 13, 2025 · 9 comments
Open

ios and flutter mixing, Open file error #322

unti1you opened this issue Jan 13, 2025 · 9 comments

Comments

@unti1you
Copy link

[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
Copy link
Author

The Flutter module can successfully open files when run separately

@unti1you
Copy link
Author

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
Copy link
Author

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

@unti1you
Copy link
Author

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

@crazecoder
Copy link
Owner

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

@unti1you
Copy link
Author

// 下载缓存并预览文件
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

@crazecoder
Copy link
Owner

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

@unti1you
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants