Reputation: 2381
I am working on a react native application on ios. The application works fine on simulator. I tried to test the app on iPad and in works fine in debug mode but when i run the app on iPad in release mode i get an exception on a button click. The exception is:
Terminating app due to uncaught exception 'RCTFatalException: Exception '-[__NSCFNumber length]: unrecognized selector sent to instance 0x94fbee52df959691' was thrown while invoking multiSet on target RNCAsyncStorage with params (
(
(
"@TOS:deletedProjects",
1864
)
),
2573
The code which is causing this exception is:
let projects = JSON.parse(await AsyncStorage.getItem('@TOS:projects'));
console.log('projects', projects);
let index = projects.findIndex(x => x.p_id === project.p_id);
console.log(projects, index);
projects.splice(index , 1);
console.log('projects', projects);
await AsyncStorage.setItem('@TOS:projects', JSON.stringify(projects));
// await AsyncStorage.setItem('@TOS:deletedProjects', JSON.stringify(project.p_id));
let deletedProjects = await AsyncStorage.getItem('@TOS:deletedProjects')
console.log("********** " + deletedProjects);
if(deletedProjects !== '' && deletedProjects !== null && deletedProjects !== undefined){
console.log('if have deleted projects');
let combined = '"' + deletedProjects + '"' + ',' + '"' + project.p_id + '"';
console.log('combined', combined);
await AsyncStorage.setItem('@TOS:deletedProjects', combined);
}else{
console.log('if no deleted projects');
await AsyncStorage.setItem('@TOS:deletedProjects', project.p_id);
}
console.log('in success');
I am unable to understand the crashing reason as app is working perfectly fine in debug mode.
Upvotes: 4
Views: 2842
Reputation: 460
Just reiterating what @Waleed mentioned in the comments to his question. To solve this issue, you need to make sure you only ever pass strings to AsyncStorage.setItem()
.
I cannot explain why this bug only appears on iOS in a release build. I also tested an Android release build and it worked fine when I passed an integer.
Upvotes: 2