我正在为基于CocoaAsyncSocket的UDP通讯编写一个Nativescript插件,但当我试图在这个pod的上下文中执行任何异步操作时,我的应用程序就崩溃了。它似乎与iOS x {N}上的队列/线程有关,但是我还没有解决它,有什么想法吗?
下面是如何在类型记录中创建插件iOS类:
export class UdpProtocol extends NSObject implements GCDAsyncUdpSocketDelegate下面是我如何初始化我的GCDAsyncUdpSocket
let dispatchQueue = dispatch_queue_create("sendUnicast_queue", null);
let sock = GCDAsyncUdpSocket.alloc()
.initWithDelegateDelegateQueue(this, dispatchQueue);下面是我在.ts中调用的异步方法的一个例子:
sock.sendDataToHostPortWithTimeoutTag(sendData, address, port, -1, this.tag);下面是我期望被正确触发的回调:
udpSocketDidSendDataWithTag(sock: GCDAsyncUdpSocket, tag: number): void {
console.log('udpSocketDidSendDataWithTag callback');
}但不幸的是,我得到的是以下JS例外:
CONSOLE LOG file:///node_modules/@nativescript/core/inspector_modules.js:1:0: Loading inspector modules...
CONSOLE LOG file:///node_modules/@nativescript/core/inspector_modules.js:6:0: Finished loading inspector modules.
NativeScript debugger attached.
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1 0x11033960e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2 0x110388f76 -[TNSRuntimeInspector reportFatalError:]
3 0x10fc2d23b TNSInspectorUncaughtExceptionHandler
4 0x7fff23e3a36d __handleUncaughtException
5 0x7fff50ad7c05 _objc_terminate()
6 0x7fff4f926c87 std::__terminate(void (*)())
7 0x7fff4f926c29 std::terminate()
8 0x7fff519128df _dispatch_client_callout
9 0x7fff5191860c _dispatch_lane_serial_drain
10 0x7fff51919044 _dispatch_lane_invoke
11 0x7fff519230c4 _dispatch_workloop_worker_thread
12 0x7fff51b37a3d _pthread_wqthread
13 0x7fff51b36b77 start_wqthread
JavaScript stack trace:
UIApplicationMain(file:///node_modules/@nativescript/core/application/application.js:312:0)
at run(file:///node_modules/@nativescript/core/application/application.js:312:0)
at file:///node_modules/@nativescript/angular/platform-common.js:210:0
at file:///node_modules/@nativescript/angular/platform-common.js:111:0
at file:///node_modules/@nativescript/angular/platform-common.js:91:0
at file:///app/bundle.js:198:144
at ./main.ts(file:///app/bundle.js:203:34)
at __webpack_require__(file:///src/webpack/bootstrap:750:0)
at checkDeferredModules(file:///src/webpack/bootstrap:43:0)
at webpackJsonpCallback(file:///src/webpack/bootstrap:30:0)
at anonymous(file:///app/bundle.js:2:61)
at evaluate([native code])
at moduleEvaluation([native code])
at [native code]
at asyncFunctionResume([native code])
at [native code]
at promiseReactionJob([native code])
JavaScript error:
file:///node_modules/@nativescript/core/application/application.js:312:0: JS ERROR Error: -[__NSCFString bytes]: unrecognized selector sent to instance 0x6000036496c0
NativeScript caught signal 6.
Native Stack:
1 0x11038a251 sig_handler(int)
2 0x7fff51b2f5fd _sigtramp
3 0x7fff51a23f39 itoa64
4 0x7fff51a1fb7c abort
5 0x7fff4f927858 abort_message
6 0x7fff4f926cad std::__terminate(void (*)())
7 0x7fff4f926c29 std::terminate()
8 0x7fff519128df _dispatch_client_callout
9 0x7fff5191860c _dispatch_lane_serial_drain
10 0x7fff51919044 _dispatch_lane_invoke
11 0x7fff519230c4 _dispatch_workloop_worker_thread
12 0x7fff51b37a3d _pthread_wqthread
13 0x7fff51b36b77 start_wqthread
JS Stack unavailable. Current thread hasn't initialized a {N} runtime.我已经尝试过像这个这里这样的解决方案,但没有成功。
导致此问题的角度演示插件可在这个布拉奇中使用。
欢迎任何建议或帮助:)
发布于 2020-04-23 13:59:42
实际上,我发现这个错误与我创建sendData变量的方式有关,我已经将它更改为:
let sendData: any = NSString.alloc().initWithCString(msg);至
const sendData: NSData = NSData.alloc().initWithBase64EncodedStringOptions(msg, 1);https://stackoverflow.com/questions/61274176
复制相似问题