iosfacebookfbsdk

How to Connect the App Delegate in Facebook SDK for iOS?


i'm trying to setup the Facebook SDK Login for IOS following the Step 3: Connect the App Delegate enter image description here

I couldn't find the AppDelegate.swift file.

Should I override the whole AppDelegate.m file with the following code?

//  AppDelegate.swift

import UIKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
          
        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )

        return true
    }
          
    func application(
        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {

        ApplicationDelegate.shared.application(
            app,
            open: url,
            sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: options[UIApplication.OpenURLOptionsKey.annotation]
        )

    }  

}

Solution

  • As I understand your iOS app is created and implemented using Objective C and so your not able to see AppDelegate.swift, If you want AppDelegate.swift then you have to create your iOS app using Swift.

    AppDelegate.h/m files in Objective C are equivalent to AppDelegate.swift file in swift.

    The Facebook SDK document you are referencing has given instruction with respect to swift iOS app.

    You can refer below link for some Objective C code as well: https://developers.facebook.com/docs/facebook-login/ios?sdk=fbsdk

    There is no mention of Objective C in step 5. Connect Your App Delegate . However, I think you can skip this step and try from Step 6. Add Facebook Login to Your Code.(This step has both Swift and Objective-C code example.