React-native-fetch-blob: openDocument not working on iOS

Created on 15 Oct 2016  路  8Comments  路  Source: wkh237/react-native-fetch-blob

RNFetchBlob.ios.openDocument: Not worked without throwing any error. it only return null result on success promise.
It also not throw error when file is not exists.

iOS: 10 (simulator)
react-native: 0.34.1
path: /Users/raminious/Library/Developer/CoreSimulator/Devices/AFCFB1EA-23C3-4B77-961C-CC431B55D4CF/data/Containers/Data/Application/324FD0EB-73B7-4EE7-9254-3C4B67857D92/Documents/myvid.mp4

beta bug ios

Most helpful comment

Thanks for the advice, if the naming is confusing, I think it's okay to change their name 馃槃 I'll make these changes and publish another package to npm.

All 8 comments

I'm not iOS developer but I changed

presentOpenInMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view

to

presentOptionsMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view

And now it's working.

@raminious , thanks for the information, I'll try to change the implementation 馃憤

Thanks @wkh237
I think as you documented openDocument must open file directly with associated app and previewDocument must show action menu for interact with the file (presentOptionsMenuFromRect)
Currently these functions are working vice versa.

Thanks for the advice, if the naming is confusing, I think it's okay to change their name 馃槃 I'll make these changes and publish another package to npm.

@raminious , I've published 0.10.0-beta.3 to npm, please upgrade to this version and verify the changes, thank you !

Thanks @wkh237

One more very important thing... the path must have an extension on the end or it won't work.

e.g. RNFetchBlob.ios.openDocument('path/to/file.ext');

the same is true for previewDocument( ). If your path doesn't have an extension, you can append the extension type on the end of the path using the .config method:

    RNFetchBlob
    .config({
      fileCache: true,
      appendExt: 'jpg', // only append an extension if the res.path() does not return one
    })
    .fetch('GET', attachmentUrl, {
      Authorization: AuthorizationStore.getAuthHeaderValue(),
    })
    .then((res) => {
      // console.log(res.path()) // uncomment this to check if your path has an extension on the end of it
      if (Platform.OS === 'ios') {
        RNFetchBlob.ios.openDocument(res.path()); // results in path/to/file.jpg
      }
    });

I filed the same issue here: https://github.com/wkh237/react-native-fetch-blob/issues/195

hi @raminious
i am not able to use the openDocument function . i checked wheter the file exists using ,
RNFetchBlob.fs.exists(fs.dirs.DocumentDir+'/sample.pdf') and it does return true. However,
when i try to do this RNFetchBlob.ios.openDocument(fs.dirs.DocumentDir+'/sample.pdf') , it does not do anything nor throw any errors, please help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jason0112 picture Jason0112  路  3Comments

NarendraSingh88 picture NarendraSingh88  路  3Comments

timsuchanek picture timsuchanek  路  4Comments

yaronlevi picture yaronlevi  路  4Comments

nicholasstephan picture nicholasstephan  路  3Comments