ios - React Native 应用程序在 Release模式下崩溃但在 Debug模式下运行良好

标签 ios react-native

我正在 ios 上开发一个 React Native 应用程序。该应用程序在模拟器上运行良好。我尝试在 iPad 上测试该应用程序,并且在 Debug模式下运行良好,但是当我在 iPad 上以 Release模式运行该应用程序时,单击按钮时出现异常。异常(exception)情况是:

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

导致这个异常的代码是:

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

我无法理解崩溃的原因,因为应用程序在 Debug模式下运行良好。

最佳答案

只是重申@Waleed 在对他的问题的评论中提到的内容。要解决此问题,您需要确保只将字符串传递给 AsyncStorage.setItem()

我无法解释为什么这个错误只出现在 iOS 的发布版本中。我还测试了一个 Android 发布版本,当我传递一个整数时它工作正常。

关于ios - React Native 应用程序在 Release模式下崩溃但在 Debug模式下运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57722157/

相关文章:

ios - TableView 索引被剪裁在底部

reactjs - React-nativeanimate.event 自定义 onScroll 监听器

javascript - react native : sending events from android to javascript

ios - React Native 中的 Release模式诊断

ios - UIView 底边模式

iphone - ios bool 变量声明

ios - NSDateFormatter - "Yesterday, 3:30 PM"

ios - 嵌入 segue - 动态切换初始 UIViewController 和包含的 UIViewController

ios - 尝试执行 pod install "[!] FBReactNativeSpec has added 1 script phase."时出现错误

javascript - react-native limit 列表项