我使用的AsyncStorage.clear()在Android上运行正常,但是在使用iOS平台(真实设备)运行时,出现此错误,无法在线找到任何相关信息。

Error: Failed to delete storage directory.Error Domain=NSCocoaErrorDomain Code=4 "“RCTAsyncLocalStorage_V1” couldn’t be removed." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/281A6456-6CB2-47D4-AD04-3EB26A1B9506/Documents/RCTAsyncLocalStorage_V1, NSUserStringVariant=(
    Remove
), NSUnderlyingError=0x174049480 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Error: Failed to delete storage directory.Error Domain=NSCocoaErrorDomain Code=4 "“RCTAsyncLocalStorage_V1” couldn’t be removed." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/281A6456-6CB2-47D4-AD04-3EB26A1B9506/Documents/RCTAsyncLocalStorage_V1, NSUserStringVariant=(
    Remove
), NSUnderlyingError=0x174049480 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
    at convertError (http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:52255:13)
    at http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:52109:18
    at MessageQueue.__invokeCallback (http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:2060:16)
    at http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1853:15
    at MessageQueue.__guard (http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1991:9)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://192.168.1.33.xip.io:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1852:13)
    at t (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/RNDebuggerWorker.js:1:14632)

最佳答案

我认为,在从未使用过存储的情况下,clear抛出异常是很糟糕的。至少那是我在想的情况?

因此,继续前进,我修改了代码,删除了.clear()的使用并将其替换为AsyncStorage.getAllKeys().then(AsyncStorage.multiRemove)
如果有人知道发生了什么,我仍然想知道一个原因。

关于ios - React-Native AsyncStorage.clear()在IOS上失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46736268/

10-10 02:27