Andrew Jang
Andrew Jang

Reputation: 191

SwiftUI Facebook SDK : App ID not found. Add a string value with your app ID for the key FacebookAppID to the Info.plist

I have added the the correct Facebook sdk values into info.plist as the Quick Start guide shows & added the SDK using the package manager, but I still get this error

Thread 1: App ID not found. Add a string value with your app ID for the key FacebookAppID to the Info.plist or call [FBSDKSettings setAppID:].

The app Id is 100% correct & it is in my info.plist. If I set the name & app Id in my app delegate I just get this error instead:

Thread 1: fbappid is not registered as a URL scheme. Please add it in your Info.plist

It seems as though the Facebook SDK can't find any values in my info.plist?

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb823445029398455</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>823445029398455</string>
    <key>FacebookDisplayName</key>
    <string>vertoo-dev</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fbapi20130214</string>
        <string>fbapi20130410</string>
        <string>fbapi20130702</string>
        <string>fbapi20131010</string>
        <string>fbapi20131219</string>
        <string>fbapi20140410</string>
        <string>fbapi20140116</string>
        <string>fbapi20150313</string>
        <string>fbapi20150629</string>
        <string>fbapi20160328</string>
        <string>fbauth</string>
        <string>fb-messenger-share-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>

This is a screenshot of my error

Upvotes: 19

Views: 15862

Answers (6)

Michael May
Michael May

Reputation: 376

Make sure the following key-value pairs

<key>FacebookAppID</key>
<string>823445029398455</string>
<key>FacebookDisplayName</key>
<string>vertoo-dev</string>

is put at the top level of the plist file instead of being nested within any other key-value pair.

Upvotes: 1

andylee
andylee

Reputation: 433

you should initialize sdk on start, as stated here

https://github.com/facebook/facebook-ios-sdk/issues/1745

The other answers do that, but they make you use UIApplicationDelegate from UIKit. If you want to just do it from swiftui, just add onappear on your contentview in your app file:

var body: some Scene {
        WindowGroup {
            ContentView()
                .onAppear(){
                    ApplicationDelegate.shared.application(UIApplication.shared, didFinishLaunchingWithOptions: nil)
                }
        }

Upvotes: 2

Abdalah Ahmed
Abdalah Ahmed

Reputation: 1

in SwiftUI

1- make sure that the file name is Info.plist - with capital "I".

2-if you faced an error says "Multiple commands produce....Info.plist",

Solution:

Open target -> Build phases > Copy Bundle Resources and remove Info.plist from there.

Upvotes: 0

miletliyusuf
miletliyusuf

Reputation: 1022

I had the same issue because I forgot to add fb as prefix of App Id in URL Schemes.

Make sure that you've added like this fb{app_id} into url schemes like image below.

enter image description here

Navigation to here: Project Navigator > Select Your Target > Info > URL Types

Upvotes: 7

Pramodya Abeysinghe
Pramodya Abeysinghe

Reputation: 1210

Tested in Xcode 12.5

make an AppDelegate.swift and add this code below.

import SwiftUI
import FacebookCore

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return ApplicationDelegate.shared.application(app, open: url, options: options)
    }
}

next in your @main App file add this line

 @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

Upvotes: 8

Ahmed Al-Imran
Ahmed Al-Imran

Reputation: 291

Add this in new file

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // Initialize Facebook SDK
        FBSDKCoreKit.ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
        return true
    }
}

Upvotes: 29

Related Questions