让react-native-fbsdk与CocoaPods一起使用

问题描述 投票:2回答:3

我一直在努力让react-native-fbsdk与CocoaPods合作,因为我更喜欢将Facebook SDK作为pod install流程的一部分,但我没有太多运气。我知道我可以react-native link npm库并手动下载并添加必要的框架,但是当我拥有一个非常好的包管理器时,这似乎相当愚蠢。

the documentation来看它应该是相当直接的 - 只需将必要的豆荚添加到Podfile,对吧?但无论我尝试什么,原始FBSDK模块似乎永远不会被包括在内。我尝试过一系列不同的Podfiles,其中一些有use_framework!pod 'Bolts',有些只有pod 'FBSDKCoreKit'。这是我目前正在使用的那个:

target 'FacebookPods' do
  pod 'FBSDKCoreKit'
  pod 'FBSDKShareKit'
  pod 'FBSDKLoginKit'

  target 'FacebookPodsTests' do
    inherit! :search_paths
  end
end

但是,当我运行我的测试应用程序并尝试使用react-native-fbsdk模块做任何事情时,我得到错误抱怨各种本机模块未定义。这是我的index.ios.js文件,试图访问LoginManager

import React, {Component} from "react"
import {AppRegistry, Text} from "react-native"
import {LoginManager} from "react-native-fbsdk"

export default class FacebookPods extends Component {
  componentWillMount() {
    LoginManager.logInWithReadPermissions(["email"])
      .then(() => console.log("Success!"))
      .catch((err) => console.log("Failure!", err))
  }

  render() {
    return <Text>Hello World</Text>
  }
}

AppRegistry.registerComponent("FacebookPods", () => FacebookPods)

但这会引发undefined is not an object (evaluating 'LoginManager.logInWithReadPermissions'中的错误FBLoginManager.js。对NativeModules的进一步检查表明,根本不包含本机FBSDK模块。我在发布时也会收到以下警告:

2017-07-13 19:50:19.006 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLikeView" does not exist
2017-07-13 19:50:19.007 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLoginButton" does not exist
2017-07-13 19:50:19.008 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBSendButton" does not exist
2017-07-13 19:50:19.009 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBShareButton" does not exist

所以,是的,我完全失去了。在我看来,简单地添加pod应该足以包含框架。我已经搜索了我可能已经错过的任何其他步骤的互联网,但除了react-native-fbsdk项目上的一些问题之后已经被删除之外没有太多。

react-native react-native-ios fbsdk react-native-fbsdk fbsdkloginkit
3个回答
8
投票

我遇到了这个问题,并设法让react-native-fbsdk使用安装的Facebook SDK,将以下内容添加到我的pod文件中:

pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'

并在AppDelegate.m中导入以下内容:

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

请注意,这些导入与react-native-fbsdk自述文件中的建议不同。那是因为没有FBSDKCorekit.frameworkFBSDKShareKit.frameworkFBSDKLoginKit.framework

您还需要从Xcode中的libFBSDKShareKit.a选项卡链接libFBSDKCoreKit.alibFBSDKLoginKit.aGeneral。这些是唯一可用于链接的三个核心/登录/共享内容。他们引用pods,看看pods目录,你看到没有.framework文件,只有.h文件,所以这些是我们导入AppDelegate.m的文件。那(我认为)为react-native-fbsdk提供了所需的SDK组件中的所有文件。


6
投票

它以我的Podfile设置方式为我工作(不确定需要Bolts框架pod):

pod 'Bolts' pod 'FBSDKCoreKit' pod 'FBSDKLoginKit' pod 'FBSDKShareKit'

我不得不做react-native link以确保libRCTFBSDK.a在xcode的Build TARGET => build phrase =>“Link Binary with libraries”列表中。如果没有,您可能需要手动添加libRCTFBSDK.a。我发现,一旦我运行react-native link并且libRCTFBSDK.a在该列表中,xCode然后正确编译。


0
投票

如果您使用cocoapods,本机将使用cocoapods链接链接库。我创建了一个新项目,然后在运行'pod init'和'pod install'之前安装并链接所有包。也许这个错误来自cocoapods链接包时。所有软件包都需要在运行'pod install'后安装的“react-native link”无法正常工作。我想我们可以在运行反应原生链接之前解封cocoapod。

© www.soinside.com 2019 - 2024. All rights reserved.