[英]NativeScript plugin crashes in external ng2 projects (not the demo)
The plugin in question is: https://github.com/sean-perkins/nativescript-opentok/tree/delegate-exploration . 有问题的插件是: https : //github.com/sean-perkins/nativescript-opentok/tree/delegate-exploration 。 If you npm install and set the build version to 1.4.4
you will get the up-to-date test version for this bug. 如果您安装npm并将构建版本设置为1.4.4
,则将获得此错误的最新测试版本。
The plugin experiences two issues: 该插件遇到两个问题:
At first, the new constructor declaration style for {N} is not recognized, so I have to fall-back to the old-school Class.alloc().initWith
declaration style. 首先,无法识别{N}的新构造函数声明样式,因此我不得不退回到老式的Class.alloc().initWith
声明样式。 I believe this may actually be related to #2. 我相信这实际上可能与#2有关。
Upon updating the constructor, the same line of code will fail with: [__NSCFNumber length]: unrecognized selector sent to instance 0xb00000002b879aa2
. 更新构造函数后,同一行代码将失败,并带有以下内容: [__NSCFNumber length]: unrecognized selector sent to instance 0xb00000002b879aa2
。
The code in question is: 有问题的代码是:
public static initWithApiKeySessionIdToken(apiKey: string, sessionId: string, token:string): TNSOTSession {
let instance = <TNSOTSession>TNSOTSession.new();
instance.events = new Observable();
instance.session = OTSession.alloc().initWithApiKeySessionIdDelegate(apiKey, sessionId, instance);
let errorRef = new interop.Reference();
instance.session.connectWithTokenError(token, errorRef);
if(errorRef.value) {
console.log(errorRef.value);
}
return instance;
}
The class ( TNSOTSession
) extends NSObject
and implements the protocol for OTSessionDelegate
, which should maintain the selector instances, as per {N} docs: 类( TNSOTSession
)扩展了NSObject
并为OTSessionDelegate
实现了协议,该协议应根据{N} docs维护选择器实例:
"Methods that are overridden will infer their signatures from the base class or protocols they implement." “被重写的方法将从其实现的基类或协议中推断出其签名。”
Ref: https://docs.nativescript.org/runtimes/ios/how-to/ObjC-Subclassing 参考: https : //docs.nativescript.org/runtimes/ios/how-to/ObjC-Subclassing
If you need to view the iOS API documentation for OpenTok, please refer to: https://www.tokbox.com/developer/sdks/ios/reference/Classes/OTSession.html . 如果您需要查看OpenTok的iOS API文档,请参阅: https ://www.tokbox.com/developer/sdks/ios/reference/Classes/OTSession.html。
Thank you to anyone that can help me move forward on this issue. 谢谢任何可以帮助我在这个问题上前进的人。 The demo works perfectly. 该演示非常完美。 The issue is found in a {N} + Angular 2 test project. 该问题在{N} + Angular 2测试项目中找到。
For anyone that runs into this issue, be sure that if your plugin has a numeric API key or any value for that matter, that is expected to be a string... be sure to cast it as a string with .toString()
. 对于遇到此问题的任何人,请确保如果您的插件具有数字API密钥或与此相关的任何值,则该字符串应为字符串...请务必使用.toString()
将其转换为字符串。 My whole issue was focused around that one small minor detail. 我的整个问题集中在一个小细节上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.