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

Access to shared item in iOS not working #26

Open
perelin opened this issue Jul 1, 2020 · 3 comments
Open

Access to shared item in iOS not working #26

perelin opened this issue Jul 1, 2020 · 3 comments

Comments

@perelin
Copy link

perelin commented Jul 1, 2020

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-

@Zapmobilegames
Copy link

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

@uiktiomasfeliz
Copy link

uiktiomasfeliz commented Jan 5, 2021

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

@roxteddy
Copy link

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.

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

4 participants