问题
I'm currently developing an App for Android / iOS, and now i'm at the stage to let my users interact with Facebook, and especially send private message to their friends.
Facebook implement a SDK for that, for iOS:
FBSDKSendButton *button = [[FBSDKSendButton alloc] init];
button.shareContent = content;
[self.view addSubview:button];
And for android:
SendButton sendButton = (SendButton)findViewById(R.id.fb_send_button);
sendButton.setShareContent(shareContent);
sendButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
But i'm unsure if i can actually use those pieces of code with NativeScript. Does anyone have any experience with facebook send button and NativeScript or at least could shed a light on whether its possible or not.
Thanks a lot
回答1:
There is something similar done in this NativeScript plugin. It provides Facebook login functionality but I believe that it would be fairly easy to make it fit your needs.
回答2:
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
来源:https://stackoverflow.com/questions/36007079/inject-pure-java-obj-c-code-in-nativescript-app