I’m developing a React Native app for tvOS and encountering a file system permission error when trying to save data using react-native-fs. The idea is to get the data from API and save it to a JSON file. The app works fine in the simulator, but when
distributed through TestFlight and run on a real tvOS device, I get the following error:
Error saving playlists to file: Error: You don’t have permission to save the file “playlist” in the folder “amazingkids”.
Error code: ENSCOCOAERRORDOMAIN513
const APP_FOLDER = RNFS.DocumentDirectoryPath +`/${APP_FOLDER_NAME}`;
const PLAYLIST_FOLDER = APP_FOLDER + '/playlist';
const PLAYLIST_FILE = PLAYLIST_FOLDER + '/playlist.json';
const savePlaylistsToFile = async (data) => {
try {
const folderExists = await RNFS.exists(PLAYLIST_FOLDER);
if (!folderExists) {
await RNFS.mkdir(PLAYLIST_FOLDER, { intermediates: true });
console.log('Playlist folder created');
}
await RNFS.writeFile(PLAYLIST_FILE, JSON.stringify(data), 'utf8');
console.log('Playlists saved to file');
} catch (err) {
console.error('Error saving playlists to file:', err.message, 'Code:', err.code);
}
};
The app works as expected in the simulator, but fails only on the TestFlight build on a real tvOS device.
Questions:
What could be causing this permission error specifically in the TestFlight environment?
Are there any tvOS-specific considerations for file system access that I’m missing?
Are there alternative storage solutions that would be more reliable for tvOS in a production environment?
I tried Using different directories (DocumentDirectoryPath, CachesDirectoryPath)
Jijith Jayakumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.