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

时间:2014-04-01 08:36:35

标签: ios cordova plugins phonegap-plugins

有没有人知道哪个是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');
        }
    }
);

如果我创建<img src="examplePicture.jpg">标记,图片将正确显示。 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 handleFailureInMethod:object: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对象也可以在应用程序中使用,因此插件似乎安装正确

1 个答案:

答案 0 :(得分:2)

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

fileURL  = [NSURL URLWithString:path]; 

fileURL  = [NSURL fileURLWithPath:path]; 

对于Cordova 3.4.0(及更高版本):如果您有来自Filesystem的条目而不是&#39; examplePicture.jpg&#39;对第一个参数使用entry.toNativeURL()。