How to get a file into the app bundle (react native ios)

140 Views Asked by At

I have been searching online for an answer and cannot seem to find a viable solution anywhere. I have a file, "sudokus.csv" that contains a large number of sudokus that my app accesses. When defining a full file path, and using the iOS simulator, this works fine. however, when I transfer the app to device, it can't find the file (understandable.) Xcode doesn't seem to be including the file anywhere in the bundled application, which I need it to do for the app to function, how do I tell it to do this? I am using RNFS to read the file, and originally, I had a server hosting this file (and returning sudokus one at a time) however I need it to work completely offline, and so I wanted to put the file directly onto the device. I can't do that, however, if it is never being transferred to the device in the first place. As I said, there is a very large number of records in the CSV file so creating a data.json and using require() isn't an option. require() expects the file to be either an image or a Json file, so that isn't going to work either. following is working.

RNFS.read("/Users/username/Documents/git_repos/app_name/ios/sudokusLocal.csv").then(str => {...})

but for this code

RNFS.read("./sudokusLocal.csv").then(str => {...}) 

I was expecting to work, but this tells me the file doesn't exist. Why is the file not being bundled and how do I combat this?

0

There are 0 best solutions below