Skip to content

Facebook Ios Integration

Sanu gupta edited this page Aug 2, 2022 · 4 revisions

Flutter iOS <> Facebook integration

To integrate Facebook SDK into your app.

Just need to follow the below implementation.

  • First add the Facebook SDK in the iOS project Podfile. Below are the Facebook SDK which need to add on Podfile.

pod 'FBSDKCoreKit'

Also check the below screenshot for the reference

Screenshot 2022-08-02 at 2 52 05 PM
  • After that need to run the below command on the terminal for updating the Pod file.

pod install

This is something look like the below screenshot

Screenshot 2022-08-02 at 3 24 18 PM
  • Second, you need to add some line of code in the info.plist which is mentioned below
<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb[Replace with App id]</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>[Replace with App id]</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>[Replace with app name]</string>
<key>FacebookAutoLogAppEventsEnabled</key>
<true/>
<key>FacebookAdvertiserIDCollectionEnabled</key>
<true/>

In the above code, you need to replace with your app info values.

  • fb[Replace with App id] // Place your iOS AppId here - fb28684XXXXX36682

  • [Replace with App id] // Place your AppId here - 28684XXXXX36682

  • FACEBOOK-CLIENT-TOKEN // Place your Client token here - 961XXX32c8685XXXXXXXXXXXfdeb9fa2

  • [Replace with app name] // Place your app name here - AppName

Also, you can check the screenshot below for the reference

Screenshot 2022-08-02 at 3 45 42 PM
  • After following the above steps, you need to add some line of code in AppDelegate.swift class

Import the FB sdk in the class - import FBSDKCoreKit and add the below code

ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions )

Please check below the example of the above code.

import UIKit
import Flutter
import FBSDKCoreKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
   
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      ApplicationDelegate.shared.application(application,didFinishLaunchingWithOptions: launchOptions)
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
   
  }

}

Also, Check the screenshot of the class below

Screenshot 2022-08-02 at 4 02 48 PM
Clone this wiki locally