0

I have files in assets folder which is created in Xcode under my_project/assets. I can normally access file in my template WebView with:

source={uri:'ICF-Package/ICFPackage/index.html'}

but I can't copy this file to LibraryDirectoryPath with react-native-fs:

RNFS.copyFile('.ICF-Package/ICFPackage/index.html', RNFS.LibraryaDirectory + '/index.html').then((result) => console.log('DONE')).catch((error) => console.log(error, 'ERROR'));

Please help me with this.

1 Answers1

0

the file copy is under in the ios asset files. but you pass the sourcePath to the method is relative to the react-native path. it means the same folder as the component that requires it.
one way, you move the file into the react-native directory, then use it. It also has an advantage, for android, it also works.
the other way, you put the file for different platforms in different files. For android, put it in the assets, for ios put it in the RNFS.MainBundlePath. The asset destination and the main.jsbundle have to be in the same folder, RNFS.MainBundlePath is the main.jsbundle path.

//for android
if(Platform.OS == "android"){
RNFS.copyFileAssets("file path under the assets",destPath)
} else {
//for ios
RNFS.copyFile(RNFS.MainBundlePath + "the path under ios assets",destPath)
Lenoarod
  • 2,504
  • 12
  • 20