首页 > 解决方案 > 在 NativeScript 中无法连接到 Facebook

问题描述

我已经安装了吊舱

pod 'FacebookSDK',

吊舱“FBSDKCoreKit”

吊舱'FBSDKLoginKit'

这是正确安装的。通过 pod 文件。

我的 app.js 中的代码

const application = require("tns-core-modules/application"); 
if(application.ios){
var AppDelegate = NSObject.extend({
       applicationDidFinishLaunchingWithOptions :function (application, launchOptions) {
         var gglDelegate = false;
         try {
            var errorRef = new interop.Reference();
            GGLContext.sharedInstance().configureWithError(errorRef);
            var signIn = GIDSignIn.sharedInstance();
            gglDelegate = true;
        } catch (error) {  console.log(error);    }
        var fcbDelegate = FBSDKApplicationDelegate.sharedInstance().applicationDidFinishLaunchingWithOptions(application, launchOptions); // facebook login delegate
                                  return gglDelegate || fcbDelegate;
      },
     applicationOpenURLSourceApplicationAnnotation : function (application, url, sourceApplication, annotation) {
         var fcbDelegate = FBSDKApplicationDelegate.sharedInstance().applicationOpenURLSourceApplicationAnnotation(application, url, sourceApplication, annotation); // facebook login delegate
          var gglDelegate = GIDSignIn.sharedInstance().handleURLSourceApplicationAnnotation(url, sourceApplication, annotation); // google login delegate
           return fcbDelegate || gglDelegate;
        }                         
},{
     name: "AppDelegate",
     ObjCProtocols:[UIApplicationDelegate , UIResponder ]  
});  
}
application.run({ moduleName: "app-root" });

我正在尝试使用演示https://github.com/mkloubert/nativescript-social-login/tree/master/demo,但在我的项目中。但我没有使用任何 nativescript 框架。我的项目基于简单的纯 javascript demo.typescript 或 angular 不适用于我的项目。

但我仍然有这个错误

在此处输入图像描述

标签: facebook-javascript-sdknativescript

解决方案


看起来你的语法不正确。扩展UIResponder并使用protocols而不是ObjCProtocols将其作为第二个参数传递给扩展函数。

var AppDelegate = UIResponder.extend({
    ....
    ....
}, {
    name: "AppDelegate",
    protocols: [UIApplicationDelegate]
});

并在运行应用程序之前设置委托,

application.ios.delegate = AppDelegate

推荐阅读