简体   繁体   中英

React Native app crashes in release mode but works fine in debug mode

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM