我遇到了尝试将数据传递给Obj-C方法时出现的错误。
代码如图所示,Obj-C:
RCT_EXPORT_METHOD(connect:(NSDictionary *) params) {
_connection = [_phone connect:params delegate:self];
}
JS:
Twilio.connect({To: '+447842111281'});
问题源于处理NSDictionary,但我无法看到数据存在问题。任何见解都将不胜感激。
堆栈跟踪如下:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d94f34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010c4f921e objc_exception_throw + 48
2 CoreFoundation 0x000000010d865d8f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 351
3 CoreFoundation 0x000000010d865bfb +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
4 reactNativeRogChapTwilio 0x000000010b783107 -[TCConnectionInternal provideStats] + 1384
5 reactNativeRogChapTwilio 0x000000010b79fdb9 __21-[TCRTCMonitor start]_block_invoke + 70
6 libdispatch.dylib 0x00000001118e40cd _dispatch_client_callout + 8
7 libdispatch.dylib 0x00000001118c01c3 _dispatch_continuation_pop + 1091
8 libdispatch.dylib 0x00000001118d51e2 _dispatch_source_latch_and_call + 195
9 libdispatch.dylib 0x00000001118cdd7d _dispatch_source_invoke + 1098
10 libdispatch.dylib 0x00000001118c4b2e _dispatch_main_queue_callback_4CF + 1006
11 CoreFoundation 0x000000010d9134f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
12 CoreFoundation 0x000000010d8d8f8d __CFRunLoopRun + 2205
13 CoreFoundation 0x000000010d8d8494 CFRunLoopRunSpecific + 420
14 GraphicsServices 0x00000001132cda6f GSEventRunModal + 161
15 UIKit 0x000000010ff9df34 UIApplicationMain + 159
16 reactNativeRogChapTwilio 0x000000010b77d2ef main + 111
17 libdyld.dylib 0x000000011193068d start + 1
18 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
答案 0 :(得分:2)
这可能与您的问题有关,也可能与您无关。但是这个错误对我来说很重要,因为params
节点数据返回时没有转换类。哪个Objective-C非常挑剔。
例如,如果我提出一个断点,我会得到这个:
po params[@"callerUserName"]
<extracting data from value failed>
我找到的解决方案是这样投射:
po ((NSString*)params[@"callerUserName"])
超级好奇为什么会发生这种情况!因为对于我的一些方法,数据传递得很好。但是如果我的字符串中只有一个整数值(例如一个带有数字的电子邮件),那么Obj-C 不知道如何处理自己。