This guide shows you how to integrate your iOS app with Facebook using the Facebook SDK for iOS.
Beginning with SDK v13.0 a Client Token is required for all calls to the Graph API.
The Facebook SDK enables:
You will need:
If You Want To | Add This Package to your project |
---|---|
Allow your app to use the Facebook services |
|
Allow users to log into your app and for your app to ask for permissions to access data |
|
Allow your app to share content on Facebook |
|
Allow users to log into your app to enable engagement and promote social features |
|
Info.plist
mit einem XML-Ausschnitt, der Daten zu deiner App enthält. Nachdem du Facebook Login integriert hast, werden App-Events automatisch für den Events Manager protokolliert und erfasst, es sei denn, du deaktivierst die automatische Protokollierung von App-Events. Detaillierte Informationen dazu, welche Daten erfasst werden und wie du die automatische Protokollierung von App-Events deaktivierst, findest du im Abschnitt Automatische Protokollierung von App-Events.
Info.plist
und wähle „Öffnen als ▸ Quellcode“ aus. <dict>...</dict>
). <array><string>
im Key [CFBundleURLSchemes]
APP-ID durch deine App-ID.<string>
im Key FacebookAppID
APP-ID durch deine App-ID.<string>
im Key FacebookClientToken
CLIENT-TOKEN durch den Wert, den du in deinem App-Dashboard unter Einstellungen > Erweitert > Client Token findest.<string>
im Key FacebookDisplayName
APP-NAME durch den Namen deiner App.Info.plist
-Datei deiner App ebenfalls Folgendes aufweisen: Du kannst die automatische Erfassung von App-Events direkt auf „true“ oder „false“ setzen, indem du FacebookAutoLogAppEventsEnabled
als Schlüssel in Info.plist
hinzufügst.
AppDelegate.swift
Methode durch folgenden Code. Dieser Code initialisiert das SDK beim Start der App und ermöglicht dem SDK, die Anmeldungen und Teilen-Vorgänge aus der nativen Facebook-App zu verarbeiten, wenn du einen Anmelde- oder Teilen-Vorgang durchführst. Ansonsten muss der*die Benutzer*in bei Facebook angemeldet sein, um den Browser in der App für die Anmeldung zu verwenden. // AppDelegate.swift import UIKit import FacebookCore @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] ) } }
SceneDelegate
. Wenn du iOS 13, füge die folgende Methode zu deinem SceneDelegate
damit Vorgänge wie das Anmelden oder die Freigabe ordnungsgemäß funktionieren: // SceneDelegate.swift import FacebookCore ... func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let url = URLContexts.first?.url else { return } ApplicationDelegate.shared.application( UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation] ) }
To learn how to implement App Events and other Facebook products to your app, click one of the buttons below.
Sharing in iOSAdd Facebook LoginAdd App EventsUse Graph API