• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 适用于 iOS 的 fileOpener2 Phonegap/cordova 插件中的正确文件路径

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:06:12 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

有没有人知道 Phonegap/cordova 应用程序的 fileOpener2 插件中文件的正确路径是什么?尤其是在 iOS 版本中 我已经试过了:

cordova.plugins.fileOpener2.open(
    'examplePicture.jpg',
    'image/jpeg',
    {
        error : function(errorObj) {
            alert('Error status: ' + errorObj.status + ' - Error message: ' + errorObj.message);
        },
        success : function () {
            alert('file opened successfully');
        }
    }
);

如果我创建一个 标签,图片将正确显示。 Safari 调试器告诉我找不到资源,如果我尝试在 iOS 模拟器中测试该资源,应用程序会因以下错误而崩溃:

2014-04-01 10:23:31.766 MobileApp[1162:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController: invalid scheme (null).  Only the file scheme is supported.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000e95e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c628b6 objc_exception_throw + 44
    2   CoreFoundation                      0x000e9448 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x01842fee -[NSAssertionHandler handleFailureInMethodbject:file:lineNumber:description:] + 116
    4   UIKit                               0x007e5a7e -[UIDocumentInteractionController setURL:] + 201
    5   UIKit                               0x007e524f -[UIDocumentInteractionController initWithURL:] + 77
    6   UIKit                               0x007e51ea +[UIDocumentInteractionController interactionControllerWithURL:] + 59
    7   MobileApp                           0x00030da5 __20-[FileOpener2 open:]_block_invoke_2 + 69
    8   libdispatch.dylib                   0x021b67f8 _dispatch_call_block_and_release + 15
    9   libdispatch.dylib                   0x021cb4b0 _dispatch_client_callout + 14
    10  libdispatch.dylib                   0x021b975e _dispatch_main_queue_callback_4CF + 340
    11  CoreFoundation                      0x0014ea5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    12  CoreFoundation                      0x0008f6bb __CFRunLoopRun + 1963
    13  CoreFoundation                      0x0008eac3 CFRunLoopRunSpecific + 467
    14  CoreFoundation                      0x0008e8db CFRunLoopRunInMode + 123
    15  GraphicsServices                    0x031049e2 GSEventRunModal + 192
    16  GraphicsServices                    0x03104809 GSEventRun + 104
    17  UIKit                               0x0034fd3b UIApplicationMain + 1225
    18  MobileApp                           0x00023bbc main + 92
    19  MobileApp                           0x00023b4d start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这个插件还有其他可以打开附件(图片、excel表格、word文档)的替代品吗?

编辑: fileOpener2 对象在应用程序中也可用,因此插件似乎安装正确



Best Answer-推荐答案


尝试更改插件的 ios 源 (Plugins/FileOpener2.m) 行

fileURL  = [NSURL URLWithString:path]; 

fileURL  = [NSURL fileURLWithPath:path]; 

对于 Cordova 3.4.0(及更高版本):如果您有来自 Filesystem 的条目而不是“examplePicture.jpg”,请使用 entry.toNativeURL() 作为第一个参数。

关于ios - 适用于 iOS 的 fileOpener2 Phonegap/cordova 插件中的正确文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22780691/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap