Search code examples
react-nativedownload

File download not working in react native for IOS


I am using "react-native-fetch-blob" version 0.10.8 to download files in react-native . This is working as expected for android. I am able to download the files as expected. Where as for ios i am not able to download the files.

Below is the code i am using.

  downloadFinalBlog() {
const { config, fs } = RNFetchBlob;
let PictureDir = fs.dirs.PictureDir; 
let options = {
  fileCache: true,
  addAndroidDownloads: {
    useDownloadManager: true, 
    notification: false,
    title: "Great ! Download Success ! :",
    mime: "application/pdf",
      description: "Final Blog"
  }
};
config(options)
   .fetch("GET", "http://www.example.com/example.pdf")

  .then(res => {
     console.log(res);

  }).catch((error) => {

    console.log(error);
  });

}

Can anyone suggest me is there any other way to download files in IOS in react native.


Solution

  • Hi had got the answer to this but forgot to answer it here.

    For ios We need to use openDocument inside the then which prompts the user to save the file to all available apps.

    Please use below code:

    .then(resp => {
          // console.log(resp);
          if (Platform.OS === "ios") {
            RNFetchBlob.ios.openDocument(resp.data);
          }
        })