SwiftUI Facebook SDK:找不到应用程序 ID。将包含您的应用 ID 的字符串值作为键 FacebookAppID 添加到 Info.plist

问题描述 投票:0回答:6

我已将正确的 Facebook sdk 值添加到 info.plist 中,如快速入门指南所示,并使用包管理器添加 SDK,但我仍然收到此错误

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:]
.

应用程序 ID 100% 正确,位于我的 info.plist 中。如果我在应用程序委托中设置名称和应用程序 ID,我只会收到此错误:

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

Facebook SDK 似乎在我的 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>

这是我的错误截图

facebook swiftui facebook-sdk-4.0
6个回答
28
投票

将其添加到新文件中

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

7
投票

在 Xcode 12.5 中测试

创建一个 AppDelegate.swift 并在下面添加此代码。

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)
    }
}

接下来在您的@main App 文件中添加此行

 @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

7
投票

我遇到了同样的问题,因为我忘记添加

fb
作为 URL 方案中 App Id 的前缀。

确保您已将这样的

fb{app_id}
添加到如下图所示的网址方案中。

enter image description here

导航至此处:项目导航器 > 选择您的目标 > 信息 > URL 类型


2
投票

您应该在启动时初始化 sdk,如此处所述

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

其他答案可以做到这一点,但它们让您使用 UIKit 中的 UIApplicationDelegate。 如果您只想从 swiftui 执行此操作,只需在应用程序文件中的 contentview 上添加 onappear 即可:

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

0
投票

在 SwiftUI 中

1- 确保文件名是 Info.plist - 大写“I”。

2-如果您遇到错误,提示“多个命令产生....Info.plist”,

解决方案:

打开目标 -> 构建阶段 > 复制捆绑资源并从其中删除 Info.plist。


0
投票

确保以下键值对

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

放置在 plist 文件的顶层,而不是嵌套在任何其他键值对中。

© www.soinside.com 2019 - 2024. All rights reserved.