AsyncStorage setItem Crashed on iOS
Value Set but application crashed.
constructor(props) {
super(props);
this.state={
valueOneResult:1,
}
this._isMounted = false;
}
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount(){
this._isMounted = false;
FinalUpdates = async ()=>{
try{
await AsyncStorage.setItem('volumeUpValue',this.state.valueOneResult);
} catch (error) {
console.log('error', error);
}
};
this._isMounted && this.setState({valueOneResult : 10})
this.FinalUpdates(),this.props.navigation.navigate('VolumeDown')
}} >
React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (2) x64 Intel(R) Pentium(R) CPU 2127U @ 1.90GHz
Memory: 147.42 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.14.1 - /usr/local/bin/node
npm: 6.9.0 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: ^0.59.8 => 0.59.8
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
Hey @Karanp13 ,
Can you provide stack trace of that error?
thanks.
Actually locally not shows any error, when I live that application and shows me crashed.
Can you please check the setitem values?
'await AsyncStorage.setItem('volumeUpValue',this.state.valueOneResult);'
@Karanp13 We are going to need logs and stack traces. The best would be if you can create a minimal repro. š
I solved using JSON.parse and JSON.stringify, Thanks
still has problem , iOS crash still happend when
let value = 1;
type of value === 'number' //true
AsyncStorage.setItem(KEY,value);
the code above will crash on release mode, but on debug mode, it is fine.
to fix this, you should do things like below
let value = "1";
type of value === 'number' //false
AsyncStorage.setItem(KEY,value);
This was a nightmare! If there is a type error please let me know while I'm developing and not when I push out to TestFlight! Come on React...
@dholbrook86 For what it's worth, we addressed this in #231.
@tido64 Fair enough. Iām on an older version. Going to update soon.
Most helpful comment
still has problem ,
iOScrash still happend whenthe code above will crash on release mode, but on debug mode, it is fine.
to fix this, you should do things like below