Search code examples
androidiosxcodereact-nativereact-native-fs

How to plant kinda file before building app and access it in react-native


I make ios, android apps with react-native.

I'm looking for method that I can plant some file in project before I build the app, and access it after it would be run.

I know some modules like "RNFetchBlob" or "react-native-fs". so I can create, read and write some files
but I've no any idea with put it in app before it would be built.

How can I put a file in before the app would be run? Can I get some clues or sample code about this?


Solution

  • I got an answer myself. so I share it.

    it's the solution for ios

    Attaching Files or directory you want to react-native ios app project

    run xcode >
    open your project ([react-native project]/[ios]) >
    right click on project that you can see at top of left side. >
    select "Add Files to "[your project name]" enter image description here

    then choose files or directory that you wanna plant in app. >
    check "Copy items if needed" >
    click Add button enter image description here

    then you can see it included at left side window enter image description here

    Accessing attached file with RNFetchBlob

    you can access attached file path in your ios app via RNFetchBlob FileSystem

    install that module to your react-native project like following command $ yarn add rn-fetch-blob

    then you can access the file like below code.

    import RNFetchBlob from 'rn-fetch-blob';
    
    const attachedFile = `${RNFetchBlob.fs.dirs.MainBundleDir}/androidVoiceRecord.m4a` ;