Brittany
Brittany

Reputation: 1439

Obj-C - Facebook iOS SDK only available for Swift?

I'm trying to install the Facebook iOS SDK in my Obj-C project, but it appears as though the FacebookSDK is only written in Swift now? Anyone have any ideas or tips on how I can integrate the Facebook SDK with my Obj-C project? Installing via CocoaPods.

Help is appreciated!

Upvotes: 0

Views: 518

Answers (1)

Maxim Strok
Maxim Strok

Reputation: 1

You can still use the Facebook iOS SDK in your Objective-C project, even though it’s primarily written in Swift now. I recommend using Swift Package Manager (SPM) for the integration, as CocoaPods is deprecated. Here’s how to do it:

  1. Add Facebook SDK via Swift Package Manager:

    • In Xcode, go to File > Add Packages....
    • Use this URL for the SDK:
      https://github.com/facebook/facebook-ios-sdk
      
    • Select the necessary libraries like FBSDKCoreKit and FBSDKLoginKit.
  2. Set up a Bridging Header:

    • If your project doesn’t have a Bridging Header, create a new Swift file in Xcode, and it will prompt you to create one. Accept it.
    • In the Bridging Header, import:
      #import <FBSDKCoreKit/FBSDKCoreKit.h>
      #import <FBSDKLoginKit/FBSDKLoginKit.h>
      
  3. Use Facebook SDK in Objective-C: In your AppDelegate.m, for example:

    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    

Alternatively, you can still use CocoaPods if you prefer, but it's deprecated. Add pod 'FacebookSDK' to your Podfile and run pod install. However, I recommend using SPM for long-term support.


This response addresses the question more directly while providing both options.

Upvotes: 0

Related Questions