让ReactNative FacebookSDK工作 [英] Getting ReactNative FacebookSDK working

查看:88
本文介绍了让ReactNative FacebookSDK工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让FBSDK在iOS ReactNative项目中运行.

I'm trying to get the FBSDK running in an iOS ReactNative project.

react-native init AwesomeProject要获得一个全新的项目,请遵循响应本机FBSDK的说明在github上,我在main.m中收到错误:

I react-native init AwesomeProject to get a brand new project, follow the React Native FBSDK instructions on github, and I get an error in main.m:

thread 1:signal SIGABRT

有点谷歌搜索使我此处然后是

A little Googling leads me here then here which has me add a LSApplicationQueriesSchemes key to my info.plist. Fixing that problem.

然后,我跟随有我的 Facebook应用设置指南除其他外,在我的info.plist`中添加NSAppTransportSecurity键.但随后,该应用程序将无法连接到开发服务器.

I then follow the Facebook app setup guide that has me add, among other things, an NSAppTransportSecurity key to my info.plist`. But then the app can't connect to the development server.

再进行一次谷歌搜索,我发现此页面说我不需要NSAppTransportSecurity键,因此我将其取出即可运行该应用程序.哇,问题解决了.

A little more googling and I find this page that says I don't need the NSAppTransportSecurity key so I take it out and the app runs. Whew, problem solved.

回到 React Native FBSDK github页面,我抓住了他们的第一个示例使用部分; LoginButton.将其逐字复制到我的应用中.它运行.我点击它.还有...

Back in the React Native FBSDK github page, I grab the first example in their usage section; the LoginButton. Copy it verbatim into my app. It runs. I click it. And...

thread 1:signal SIGABRT

啊!

有人能做到这一点吗?

Has anyone gotten this to work?

推荐答案

我有!安装SDK之后,您需要确保所有配置都是属性集.您还需要在AppDelegate中导入sdk.

I have! After installing the SDK, you need to make sure all the configurations are property set. You also need to import the sdk in your AppDelegate.

这是我info.plist中的相关配置.

Here are the relevant configs from my info.plist.

<key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>fb12345678910</string>
      </array>
    </dict>
  </array>
  <key>FacebookAppID</key>
  <string>12345678910</string>
  <key>FacebookDisplayName</key>
  <string>My Awesome App</string>


  <key>NSAppTransportSecurity</key>
  <dict>
    <key>NSExceptionDomains</key>
    <dict>
      <key>facebook.com</key>
      <dict>
        <key>NSIncludesSubdomains</key> <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
      </dict>
      <key>fbcdn.net</key>
      <dict>
        <key>NSIncludesSubdomains</key> <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>  <false/>
      </dict>
      <key>akamaihd.net</key>
      <dict>
        <key>NSIncludesSubdomains</key> <true/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
      </dict>
      <key>localhost</key>
      <dict>
        <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/>
      </dict>
      <key>api.mydomain.com</key>
      <dict>
        <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/>
      </dict>
    </dict>
  </dict>


  <key>LSApplicationQueriesSchemes</key>
  <array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
  </array>

共有三个部分:

  1. 您需要定义您的应用ID和显示名称.
  2. 您需要定义您的应用可以访问的域,显然是Facebook的域,akamai和您自己的域,我已经在列表中包括了localhost.
  3. 最后,您需要包括查询方案

这是我的AppDelegate.m文件.

``` #import"AppDelegate.h"

``` #import "AppDelegate.h"

#import "RCTRootView.h"

#import <FBSDKCoreKit/FBSDKCoreKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  /**
   * Facebook SDK
   *
   **/
  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];

  /**
   * Loading JavaScript code - uncomment the one you want.
   *
   * OPTION 1
   * Load from development server. Start the server from the repository root:
   *
   * $ npm start
   *
   * To run on device, change `localhost` to the IP address of your computer
   * (you can get this by typing `ifconfig` into the terminal and selecting the
   * `inet` value under `en0:`) and make sure your computer and iOS device are
   * on the same Wi-Fi network.
   */

  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

  /**
   * OPTION 2
   * Load from pre-bundled file on disk. The static bundle is automatically
   * generated by the "Bundle React Native code and images" build step when
   * running the project on an actual device or running the project on the
   * simulator in the "Release" build configuration.
   */

//   jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MyAwesomeApp"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

/**
 * Facebook SDK
 *
 **/

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                         openURL:url
                                               sourceApplication:sourceApplication
                                                      annotation:annotation];
}

@end

有了这些配置,我就可以连接服务器,登录用户等.

With these configurations, I'm able to connect with my server, login users, etc.

祝你好运!

这篇关于让ReactNative FacebookSDK工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆