I asked a similar question last week and was able to get use the addSubview call to work like this:
var mainView = args.object.getViewById('main-view');
mainView.ios.addSubview(publisher.view);
My XML looks like:
<Page loaded="pageLoaded">
<StackLayout id="main-view">
</StackLayout>
</Page>
You'll need an ID on the view you created in your XML, then in the code-behind file in your function, use the args.object.getViewById('yourViewID'); to create a variable and then call viewVariable.ios.addSubview('view-you-want-to-add');.
In my case my framework's publisher object is what I passed to the .ios.addSubview() call.
Full code-behind file as well:
var vmModule = require("./main-view-model");
// moving OpenTok out of the plugin and into code base for dev.
// Will move into a plugin after
var OpenTok = {
createSession: function(options) {
var apiKey = 'private';
var sessionID = 'private';
var delegate = this;
// Framework Method
var session = OTSession.alloc().init();
return session.initWithApiKeySessionIdDelegate(apiKey, sessionID, delegate);
},
createPublisher: function() {
// Framework Method
var publisher = OTPublisher.alloc().init();
return publisher;
}
};
function pageLoaded(args) {
var page = args.object;
var mainView = args.object.getViewById('main-view');
var token = "private";
var error = new interop.Reference();
page.bindingContext = vmModule.mainViewModel;
var session = OpenTok.createSession();
// Framework Method
session.connectWithTokenError(token, error);
var publisher = OpenTok.createPublisher();
// Framework Method
publisher.initWithDelegate(publisher);
// Native iOS Method
mainView.ios.addSubview(publisher.view);
var checkConnectionStatus = setInterval(function(){
if ( session.sessionConnectionStatus == 1 ) {
console.log('clear interval');
clearInterval(checkConnectionStatus);
// Framework Method
session.publishError(publisher, null);
}
}, 1000);
}
exports.pageLoaded = pageLoaded;
This is my question that might also provide more insight if you're still stuck: Nativescript addSubview