[英]File '(null)' isn't writable Exception (EXPO IOS) React Native
i'm developing an expo app in which i'm generating QR Code.i'm getting base64 string which i can save as jpg or png in gallery/album.so far, On android it is working fine as expected.But On IOS it is giving this Error我正在开发一个 expo 应用程序,我在其中生成 QR 码。我得到 base64 字符串,我可以将其另存为 jpg 或 png 在画廊/相册中。到目前为止,在 android 上它按预期工作正常。但在 IOS它给出了这个错误
File '(null)' isn't writable文件“(null)”不可写
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper promiseMethodWrapper 中的 node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50
- node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
- node_modules/expo-file-system/build/FileSystem.js:50:17 in writeAsStringAsync writeAsStringAsync 中的 node_modules/expo-file-system/build/FileSystem.js:50:17
I'm using expo FileSystem method writeAsStringAsync() Here is my Code.我正在使用 expo FileSystem 方法 writeAsStringAsync() 这是我的代码。
const filename = FileSystem.documentDirectory + `${imageName}.jpg`;
let newFile = decodeURI(filename).replace('file://', '') ;
console.log(newFile)
FileSystem.writeAsStringAsync(filename, base64Code, {
encoding: FileSystem.EncodingType.Base64,
}).then(()=>{
console.log('worked')
}).catch((e)=>{
console.log(e)
});
await MediaLibrary.saveToLibraryAsync(filename).then(()=>{
setIsSavedGallery(true);
setTimeout(showAlertGallery, 1000);
}).catch((e)=>{
console.log(e)
});
any clue on this error?关于这个错误的任何线索? how can i fix?我该如何解决? what i'm doing wrong?我做错了什么? i can't seem to understand.我似乎无法理解。 any kind of help would be appreciated.任何形式的帮助将不胜感激。 Thanks谢谢
I had the same issue.我遇到过同样的问题。 The problem with me was that there was a space on the file name, which didn't sit well on iOS, so I replaced the space with a _我的问题是文件名上有一个空格,在 iOS 上不太好,所以我用_替换了空格
I can confirm that the issue was because of space.我可以确认问题是因为空间。
I use a regex to replace them by underscore.我使用正则表达式用下划线替换它们。
title.replace(/\s/g, '_')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.