joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.8k stars 767 forks source link

IOS release crash on pdf download #834

Open FoolCoder opened 1 year ago

FoolCoder commented 1 year ago

pdf download is working of dev mode in iOS, but when I create iOS release in XCode and launch app in testflight , it crashes the app, I do not understand why? this is my code: const downloadPdf = async url => { try { const { config, fs } = RNFetchBlob; let date = new Date(); let dirs = Platform.OS == 'ios' ? fs.dirs.DocumentDir : fs.dirs.DownloadDir; let configfb = { fileCache: true, addAndroidDownloads: { //Related to the Android only useDownloadManager: true, notification: true, path: ${dirs}/test.pdf, description: 'Pdf file Download', }, }; const configOptions = Platform.select({ ios: { fileCache: configfb.fileCache, path: configfb.addAndroidDownloads.path, appendExt: 'pdf', }, android: configfb, }); config(configOptions) .fetch('GET', ${REACT_APP_API_BASE_URL}file/file?uuid=${url?.uuid}, { Authorization: Bearer ${accessToken.token}, // 'Content-Type' : 'multipart/form-data' }) .then(async res => { //Showing alert after successful downloading try { if (Platform.OS === 'ios') { RNFetchBlob.fs.writeFile(configfb.addAndroidDownloads.path, res.data, 'base64'); RNFetchBlob.ios.previewDocument(configfb.addAndroidDownloads.path);

          return true;
        } else {
          Alert.alert('Report Downloaded Successfully.');

          return true;
        }
      } catch (error) {
        Alert.alert('download fail');
      }
    })
    .catch(e => console.log('eeeee', e));
} catch (error) {
  console.log('download fail');
}

};