NativeScript plugin crashes in external ng2 projects (not the demo)

时间:2016-08-31 17:08:00

标签: javascript ios nativescript angular2-nativescript

The plugin in question is: 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.

The plugin experiences two issues:

  1. 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. 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.

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:

"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

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.

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.

1 个答案:

答案 0 :(得分:1)

对于遇到此问题的任何人,请确保如果您的插件有一个数字API密钥或任何值,那么这应该是一个字符串...请确保将其强制转换为带有{{{ 1}}。我的整个问题都集中在一个小细节上。