2016-03-15 78 views
1

我目前正在開發適用於Android/iOS的應用程序,現在我處於讓用戶與Facebook進行交互的階段,並且特別向他們的朋友發送私人消息。在NativeScript應用程序中注入純Java/Obj-C代碼

的Facebook實現SDK的是,針對iOS:

FBSDKSendButton *button = [[FBSDKSendButton alloc] init]; 
button.shareContent = content; 
[self.view addSubview:button]; 

而針對Android:

SendButton sendButton = (SendButton)findViewById(R.id.fb_send_button); 
sendButton.setShareContent(shareContent); 
sendButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... }); 

但我不確定我是否能真正使用這些代碼段與NativeScript。 有沒有人有任何與Facebook發送按鈕和NativeScript的經驗或至少可以闡明是否可能與否。

非常感謝

回答

0

上週我問過類似的問題,是能夠得到使用addSubview調用像這樣的工作:

var mainView = args.object.getViewById('main-view'); 
mainView.ios.addSubview(publisher.view); 

我的XML看起來像:

<Page loaded="pageLoaded"> 
<StackLayout id="main-view"> 
</StackLayout> 
</Page> 

你需要一個ID根據您在XML中創建的視圖,然後在函數的代碼隱藏文件中,使用args.object.getViewById('yourViewID');創建變量,然後調用viewVariable.ios.addSubview('view-you-want-to-add');

在我的情況下,我的框架的publisher對象是我傳遞給.ios.addSubview()調用。

全部代碼隱藏文件以及:

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; 

這是我的問題,可能還提供了更深入的瞭解,如果你還停留:Nativescript addSubview

相關問題