dmyma
dmyma

Reputation: 223

'FacebookSDK/FacebookSDK.h' file not found work with Parse

I am working with Parse and Facebook I have the following 2 errors:

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

  2. Failed to import bridging header

I already imported both ParseFacebookUtilsV4/PFFacebookUtils.h and ParseFacebookUtils/PFFacebookUtils.h to my bridging-header because I am doing everything with Swift.

But when I just used Parse everything working fine, so I think the problem is only with FacebookSDK.

after I installed pod file and start project here are my files:

  1. this is my app delegate

    import 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

    import UIKit

    class 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.
    }
    

    }

plist

I added this

<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 my bridging-file

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

Upvotes: 0

Views: 837

Answers (2)

SwiftArchitect
SwiftArchitect

Reputation: 48514

Facebook + Parse + Utils

Using ParseFacebookUtilsV4 to match the code in the question. I suspect you are experiencing difficulties because of multiple, incoherent libraries.

Podfile

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

SO-32302877-Bridging-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
}

View Controller

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

► Find this solution on GitHub and additional details on Swift Recipes.

Upvotes: 0

SwiftArchitect
SwiftArchitect

Reputation: 48514

Facebook SDK Swift Integration

It is likely that one of the many steps involved with this task may have gone wrong. If you start over from a fresh project, you will likely find out what step you missed. Follow the Facebook iOS Integration Tutorial below.

Create a fresh new Xcode project

Xcode > File > Project... > Single View Application > Next > Product Name SO-32302877, Language Swift > Next > Create.

Add a pod

In terminal:

cd SO-32302877
pod init

and make your Podfile like this:

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

Close Xcode project if not already done. In Terminal, run:

pod install

Import the SDK

Open SO-32302877.xcworkspace. Create a bridging header. Simplest way is to add & delete an Obj-C file. In Xcode > Navigator, select the SO-32302877 group, Xcode > File > New > File... > Cocoa Touch Class > Next > Class: ObjC, Language: Objective-C > Next > Create.

enter image description here

You can now select and delete the ObjC.h and ObjC.m files from Xcode and Move to Trash. You now have a SO-32302877-Bridging-Header.h, and the target SO-32302877 Build Settings are set up properly. In SO-32302877-Bridging-Header.h, add:

#import "FBSDKCoreKit.h"

Test Instrumentation

In your Swift implementation, invoke:

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

Built, linked, ran & tested on Xcode 7 + iOS 8.4.


To download the full project, search for SO-32302877 in Swift Recipes.

Upvotes: 0

Related Questions