cordova-plugin-openwith-ios icon indicating copy to clipboard operation
cordova-plugin-openwith-ios copied to clipboard

Access to shared item in iOS not working

Open perelin opened this issue 4 years ago • 3 comments

I´m building a Cordova app for iOS (Vue / Quasar based [1]). I use the plugin to share items (images, pdfs) from other apps to my app via the iOS Share Sheet. When the items are shared successfully a native file URI like file:///var/mobile/Media/PhotoData/OutgoingTemp/3DD09AF1-75C5-4D6E-AC04-A539DEA401E5/1b91976f-8b9e-4eba-8699-505458907b4b.JPG becomes available in my app. The docs hint that I need to use the cordova-plugin-file [3] to actually access and use the shared file.

I tried out two different ways to access the file with cordova-plugin-file (taken directly from their documentation [4][5]). Directly on a device.

Given item.data = file:///var/mobile/Media/PhotoData/OutgoingTemp/3DD09AF1-75C5-4D6E-AC04-A539DEA401E5/1b91976f-8b9e-4eba-8699-505458907b4b.JPG

First approach

        window.resolveLocalFileSystemURL(
          item.data,
          function (entry) {
            console.log('resolving')
            var nativePath = entry.toURL()
            console.log('Native URI: ' + nativePath)
          },
          function (err) {
            console.error('resolveLocalFileSystemURL', err.code)
          }
        )

... results in ERROR: resolveLocalFileSystemURL 1 (NOT_FOUND_ERR)

And second approach

        window.requestFileSystem(
          window.LocalFileSystem.TEMPORARY,
          0,
          function (fs) {
            console.log('file system open: ' + fs.name)
            fs.root.getFile(
              item.data,
              { create: false, exclusive: false },
              function (fileEntry) {
                console.log('fileEntry is file?' + fileEntry.isFile.toString())
              },
              function (err) {
                console.error('getFile', err.code)
              }
            )
          },
          function (err) {
            console.error('requestFileSystem', err.code)
          }
        )

... results in ERROR: getFile 5 (ENCODING_ERR)

I already looked extensively for possible hints to what might cause this (SO, Cordova Forums, Plugin Forums, Quasar Forums), but had no luck so far. Exploration of the plugins source code (tracing the error codes, etc) also gave me no clue to what might be the issue.

Anyone any ideas where to look next?

❯ cordova -v                                                                                              
9.0.0 ([email protected])

❯ cordova requirements                                                                                    
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-23
Gradle: installed /usr/local/Cellar/gradle/6.1.1/bin/gradle

Requirements check results for ios:
Apple macOS: installed darwin
Xcode: installed 11.5
ios-deploy: installed 1.10.0
CocoaPods: installed 1.8.4

❯ cordova plugin                                                                                         
cordova-plugin-file 6.0.2 "File"
cordova-plugin-openwith-ios 1.0.0 "OpenWith"
cordova-plugin-whitelist 1.3.4 "Whitelist"

iOS: 13.5.1

[1] https://quasar.dev [3] https://github.com/apache/cordova-plugin-file
[4] https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#cdvfile-protocol
[5] https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#sample-create-files-and-directories-write-read-and-append-files-

perelin avatar Jul 01 '20 06:07 perelin

I faced the same problem, did you got the working solution?

Zapmobilegames avatar Nov 11 '20 21:11 Zapmobilegames

i have the same problem. it seems to be the internal url. I have compared with other plugins and this is the result with same photo, the first two are shared from Photos app and the third is added with gallery plugin. Captura de pantalla 2021-01-05 a las 12 55 47

The error i got in console is: Failed to load resource: the server responded with a status of 404 () and I think is related with the iOS File System Layout https://github.com/apache/cordova-plugin-file#ios-file-system-layout

The cc.fovea.cordova.openwith on iOS return always base64 Captura de pantalla 2021-01-05 a las 13 13 51

uiktiomasfeliz avatar Jan 05 '21 12:01 uiktiomasfeliz

We noticed that when the shareextension is closed, the files are deleted from the temporary folder. We fixed that by putting a long timeout in the ios code before it closes the extension but it would be better to have some kind of .finish() method in the handler.

roxteddy avatar Jun 17 '21 09:06 roxteddy