RCTBatchedBridge。m错误:无效的数据消息—全部必须长度:%zd。本机反应,iOS模拟器

时间:2022-11-03 18:34:32

I'm using react-native-oauth and getting this error (see red image at bottom) when trying to authorise. I've searched and found only this similar unanswered question. I looked into the source and found where the error is raised on line 954 and it seems it's because moduleIDs.count should equal methodIDs.count and paramsArrays.count :

在尝试授权时,我使用的是反应-本机-oauth,并得到这个错误(见底部的红色图像)。我搜索了一下,发现了这个类似的问题。我查看了源代码,发现了错误在第954行上的位置,似乎是因为moduleid。应该等于methodIDs计数。数和paramsArrays。数:

  if (RCT_DEBUG && (moduleIDs.count != methodIDs.count || moduleIDs.count != paramsArrays.count)) {
RCTLogError(@"Invalid data message - all must be length: %zd", moduleIDs.count);

So, still in the source, I look for these objects and find them defined just above, on lines 943-945 and they are using RCTConvert, whose functions "...all accept a JSON value as input and map it to a native Objective-C type or class." - React's docs

所以,我仍然在源代码中寻找这些对象,并在上面定义它们,在943-945行,他们使用RCTConvert,它的功能是……所有人都接受JSON值作为输入,并将其映射到本地Objective-C类型或类。——反应的文档

So it seems like this is a transpiling and/or networking related error. But I have basically 0 knowledge on those fields and feel I've hit a barrier to investigating and wondered if anybody had any ideas on moving forward. Being new to React Native and never having done any Objective-C can't be helping me.

因此,这似乎是一个传输和/或网络相关的错误。但我对这些领域的知识基本上一无所知,我觉得我已经突破了调查的障碍,并且怀疑是否有人有任何关于前进的想法。作为一个新的反应本地人,从来没有做过任何Objective-C不能帮助我。

Also, here's my code generating the errors.

还有,这是我的代码生成错误。

import OAuthManager from 'react-native-oauth';
import {
Alert
} from 'react-native'
var env = require('../environment.js')
const config =  {
  facebook: {
    client_id: env.getKey("FB_ID"),
    client_Secret: env.getKey("FB_SECRET")
  }
}
const manager = new OAuthManager('myAppName')
manager.configure(config);
exports.authWithFb = () => {
   manager.authorize('facebook')
     .then(resp => Alert.alert('response!' + resp))
     .catch(err => Alert.alert('error msg here: ' + err));
}

I am guessing this undefined error is related to the RCTBridge error but not sure. You can below see when I Alert the manager.authorize's caught error. TypeError: undefined is not an object (evaluating 'fn'):

我猜测这个未定义的错误与RCTBridge错误有关,但不确定。当我通知经理时,你可以看到。授权的捕获错误。TypeError:未定义的不是一个对象(评估“fn”):

RCTBatchedBridge。m错误:无效的数据消息—全部必须长度:%zd。本机反应,iOS模拟器RCTBatchedBridge。m错误:无效的数据消息—全部必须长度:%zd。本机反应,iOS模拟器

Edit:

编辑:

When I try to Alert the config object, I get an error about not being able to stringify it's sub-object. RCTBatchedBridge。m错误:无效的数据消息—全部必须长度:%zd。本机反应,iOS模拟器

当我试图警告配置对象时,我有一个错误,就是不能把它的子对象stringify。

When looking in console in chrome debugger, I get "Cannot read property 'configureProvider' of undefined" and configureProvider() is what react-native-oauth uses so it looks like the manager is not set up right so maybe I didn't link the library well. Have checked the linking worked.

当在chrome调试器中查看控制台时,我得到“无法读取属性”的“未定义”和“配置提供程序”()的配置,这样就会导致生成的错误,所以看起来好像管理器没有设置好,所以可能我没有把库链接好。检查过链接是否有效。

Im digging into the errors a bit and it seems like a promise/callback related problem from NativeModules.OAuthManager. The error caught is: TypeError: Cannot read property 'authorize' of undefined. When I jump into the stack trace I find: RCTBatchedBridge。m错误:无效的数据消息—全部必须长度:%zd。本机反应,iOS模拟器

我正在深入研究这些错误,这看起来像是来自NativeModules.OAuthManager的一个承诺/回调相关问题。所捕获的错误是:TypeError:不能读取未定义的属性“授权”。当我进入堆栈跟踪时,我发现:

Any help is much appreciated, thanks.

非常感谢您的帮助。

2 个解决方案

#1


2  

So for me whatever was going wrong was a setup issue with react-native-oauth because everything has fixed itself since I've rolled back to a point where my code had no other dependencies (I also had Firestack installed) and set up from scratch again following react-native-oauth's docs. I realised that there was a step on iOS/XCode's side that I had missed out because when I originally tried I couldn't find the file so just skipped that step:

因此,对我来说,不管出了什么问题,都是由于我的代码没有其他依赖项(我也安装了Firestack),而我的代码没有其他依赖项(我也安装了Firestack),然后从头开始重新设置,然后再从头开始执行。我意识到iOS/XCode中有一个步骤我错过了,因为当我最初尝试时,我找不到文件,所以跳过了这个步骤:

From react-native-oauth readme

从react-native-oauth自述

Next, navigate to the neighboring "Build Phases" section of project settings, find the "Link Binary with Library" drop down, expand it, and click the "+" to add libOAuthManager.a to the list.

接下来,导航到项目设置的相邻“构建阶段”部分,找到“与库的链接二进制文件”下拉,展开它,并单击“+”添加libOAuthManager。一个列表。

The errors I were getting were a few steps removed from this but I'm sure connected somehow. Lessons learnt: don't try to do too many things at once and don't skip required steps.

我所犯的错误有几个步骤,但我肯定是有联系的。经验教训:不要尝试一次做太多的事情,也不要跳过必要的步骤。

#2


1  

You'll get this error when you will send some wrong data into native side. For example if you should pass string but you passed an object.

当您将一些错误的数据发送到本机端时,您将会得到这个错误。例如,如果您应该传递字符串,但是您传递了一个对象。

Please console.log your config variable.

请控制台。日志配置变量。

https://www.npmjs.com/package/react-native-oauth

https://www.npmjs.com/package/react-native-oauth

I guess you're sent some wrong data into native side

我猜你把一些错误的数据发送到本机。

#1


2  

So for me whatever was going wrong was a setup issue with react-native-oauth because everything has fixed itself since I've rolled back to a point where my code had no other dependencies (I also had Firestack installed) and set up from scratch again following react-native-oauth's docs. I realised that there was a step on iOS/XCode's side that I had missed out because when I originally tried I couldn't find the file so just skipped that step:

因此,对我来说,不管出了什么问题,都是由于我的代码没有其他依赖项(我也安装了Firestack),而我的代码没有其他依赖项(我也安装了Firestack),然后从头开始重新设置,然后再从头开始执行。我意识到iOS/XCode中有一个步骤我错过了,因为当我最初尝试时,我找不到文件,所以跳过了这个步骤:

From react-native-oauth readme

从react-native-oauth自述

Next, navigate to the neighboring "Build Phases" section of project settings, find the "Link Binary with Library" drop down, expand it, and click the "+" to add libOAuthManager.a to the list.

接下来,导航到项目设置的相邻“构建阶段”部分,找到“与库的链接二进制文件”下拉,展开它,并单击“+”添加libOAuthManager。一个列表。

The errors I were getting were a few steps removed from this but I'm sure connected somehow. Lessons learnt: don't try to do too many things at once and don't skip required steps.

我所犯的错误有几个步骤,但我肯定是有联系的。经验教训:不要尝试一次做太多的事情,也不要跳过必要的步骤。

#2


1  

You'll get this error when you will send some wrong data into native side. For example if you should pass string but you passed an object.

当您将一些错误的数据发送到本机端时,您将会得到这个错误。例如,如果您应该传递字符串,但是您传递了一个对象。

Please console.log your config variable.

请控制台。日志配置变量。

https://www.npmjs.com/package/react-native-oauth

https://www.npmjs.com/package/react-native-oauth

I guess you're sent some wrong data into native side

我猜你把一些错误的数据发送到本机。