找不到'FacebookSDK / FacebookSDK.h'文件与Parse一起工作

时间:2015-08-31 01:33:57

标签: facebook swift parse-platform

我正在与Parse和Facebook合作我有以下2个错误:

  
      
  1. 'FacebookSDK/FacebookSDK.h' file not found

  2.   
  3. Failed to import bridging header

  4.   

我已将ParseFacebookUtilsV4/PFFacebookUtils.hParseFacebookUtils/PFFacebookUtils.h都导入到我的桥接标题中,因为我正在使用Swift执行所有操作。

但是当我使用Parse一切正常时,我觉得问题只出现在FacebookSDK

我安装pod文件后启动项目是我的文件:

  1. 这是我的应用代表

    导入UIKit

    @UIApplicationMain class AppDelegate:UIResponder,UIApplicationDelegate {

    var window: UIWindow?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
    
        Parse.enableLocalDatastore()
    
        // Initialize Parse.
        Parse.setApplicationId(“MY_APLLICATION_ID”,
            clientKey: "MY_APLLICATION_KEY")
        PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
        // [Optional] Track statistics around application opens.
        PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
    
    
    
        return true
    }
    
    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
    
    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        FBSDKAppEvents.activateApp()
    }
    
    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    func application(application: UIApplication,
        openURL url: NSURL,
        sourceApplication: String?,
        annotation: AnyObject?) -> Bool {
            return FBSDKApplicationDelegate.sharedInstance().application(application,
                openURL: url,
                sourceApplication: sourceApplication,
                annotation: annotation)
    }
    

    }

  2. 的viewController

    导入UIKit

    类ViewController:UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        var permissions = ["public_profile"]
    
        PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
            (user: PFUser?, error: NSError?) -> Void in
            if let user = user {
                if user.isNew {
                    println("User signed up and logged in through Facebook!")
                } else {
                    println("User logged in through Facebook!")
                }
            } else {
                println("Uh oh. The user cancelled the Facebook login.")
            }
        }
    
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    }

  3. 的plist

    我添加了这个

    <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>MY_APP_KEY</string>
                </array>
            </dict>
        </array>
        <key>FacebookAppID</key>
        <string>MY_APP_KEY</string>
        <key>FacebookDisplayName</key>
        <string>MY_APP_NAME</string>
    

    4我的桥接文件

    #import "FBSDKCoreKit.h"
    #import "Parse.h"
    

2 个答案:

答案 0 :(得分:0)

Facebook SDK Swift Integration

这项任务涉及的许多步骤之一可能出错了。如果你从一个新项目开始,你可能会发现你错过了哪一步。按照下面的F acebook iOS集成教程进行操作。

创建一个全新的Xcode项目

Xcode&gt;文件&gt;项目...&gt;单视图应用&gt;下一个&gt;产品名称SO-32302877,语言 Swift &gt;下一个&gt;创建

添加广告

在终端:

cd SO-32302877
pod init

并将 Podfile 设为:

platform :ios, '8.0'
target 'SO-32302877' do
pod 'FBSDKCoreKit'
end

如果尚未完成,请关闭Xcode项目。在终端中,运行:

pod install

导入SDK

打开SO-32302877.xcworkspace。创建一个桥接头。最简单的方法是添加&amp;删除Obj-C文件。在Xcode中&gt;导航器,选择SO-32302877组,Xcode&gt;文件&gt;新&gt;文件...&gt; Cocoa Touch Class&gt;下一个&gt;分类:ObjC,语言: Objective-C &gt;下一个&gt;创建

enter image description here

您现在可以从Xcode和 Move to Trash 中选择并删除ObjC.hObjC.m个文件。您现在拥有SO-32302877-Bridging-Header.h,并且正确设置了目标SO-32302877 构建设置。 在SO-32302877-Bridging-Header.h中,添加:

#import "FBSDKCoreKit.h"

测试仪器

Swift 实现中,调用:

let token:FBSDKAccessToken = FBSDKAccessToken(
    tokenString: "tokenString",
    permissions: [],
    declinedPermissions: [],
    appID: "appID",
    userID: "userID",
    expirationDate: NSDate(),
    refreshDate: NSDate())
print("\(token)")

建立,链接,运行&amp;在Xcode 7 + iOS 8.4上测试。

要下载整个项目,请在Swift Recipes中搜索SO-32302877

答案 1 :(得分:0)

Facebook + Parse + Utils

使用ParseFacebookUtilsV4匹配问题中的代码。我怀疑你因为多个不连贯的库而遇到了困难。

<强> Podfile

platform :ios, '8.0'
target 'SO-32302877' do
pod 'FBSDKCoreKit'
pod 'Parse'
pod 'ParseFacebookUtilsV4'
end

<强> SO-32302877-桥接-Header.h

#import "FBSDKCoreKit.h"
#import "Parse.h"
#import "PFFacebookUtils.h"

<强> AppDelegate.swift

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions:
                     [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Parse.enableLocalDatastore()
    Parse.setApplicationId("applicationId", clientKey: "clientKey")
    PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)
    PFAnalytics.trackAppOpened(launchOptions: launchOptions)
    return true
}

查看控制器

let permissions = ["permissions"]
PFFacebookUtils.logInInBackground(withReadPermissions: permissions) {
    (user: PFUser?, error:Error?) in
    if let user = user {
        print("user.isNew \(user.isNew)")
    } else {
        print("!user")
    }
}

►在GitHub上找到此解决方案,并在Swift Recipes上找到其他详细信息。