2017-10-13 93 views
2

我正在使用AsyncStorage.clear(),它在Android上工作得很好,但在使用iOS平臺(實際設備)運行時出現此錯誤,無法在網上找到任何東西關於它。React-Native AsyncStorage.clear()在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) 
+0

可能將其封裝在try-catch塊中 – Cherniv

回答

2

我覺得很糟糕的是,當存儲從未被使用過時,clear會引發異常;至少我認爲這就是這種情況。

所以繼續前進我修改代碼 AsyncStorage.getAllKeys() .then(AsyncStorage.mulitRemove)

取出使用.clear()和替換它我想,如果有人知道是怎麼回事,還是喜歡一個原因。