Async-storage: AsyncStorage setItem Crashed on iOS

Created on 21 May 2019  Ā·  8Comments  Ā·  Source: react-native-async-storage/async-storage

Current behavior

AsyncStorage setItem Crashed on iOS

Expected behavior

Value Set but application crashed.

Initialise Values

constructor(props) {
super(props);
this.state={
valueOneResult:1,
}
this._isMounted = false;
}
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount(){
this._isMounted = false;

Repro steps

FinalUpdates = async ()=>{
try{
await AsyncStorage.setItem('volumeUpValue',this.state.valueOneResult);
} catch (error) {
console.log('error', error);
}
};

Update Value

this._isMounted && this.setState({valueOneResult : 10})

Function Call

onPress={() => {
this.FinalUpdates(),this.props.navigation.navigate('VolumeDown')
}} >
Click Me


Environment

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

  • Async Storage version:
    "@react-native-community/async-storage": "^1.3.4"
  • React-Native version:
    "react": "16.8.3",
    "react-native": "^0.59.8",
  • Platform tested:
    iOS
  • Logs/Error that are relevant:
bug

Most helpful comment

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);

All 8 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StevenMasini picture StevenMasini  Ā·  22Comments

Waqas-Jani picture Waqas-Jani  Ā·  28Comments

srivatsav picture srivatsav  Ā·  26Comments

cpojer picture cpojer  Ā·  34Comments

alex-mironov picture alex-mironov  Ā·  71Comments