简体   繁体   中英

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

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() . My whole issue was focused around that one small minor detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM