Следуя этому руководству: https://developers.facebook.com/docs/facebook-login/ios
Функция обратного вызова никогда не вызывается в случае успеха, она вызывается только при отмене пользователем.
Зависимость пакета — Facebook v14.1.0
iOS версии 17.6
import SwiftUI
import FBSDKLoginKit
@main
struct myapp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
FacebookLoginView()
.frame(width: 200, height: 50)
}
}
}
struct FacebookLoginView: UIViewRepresentable {
typealias UIViewType = FBLoginButton
func makeUIView(context: Context) -> UIViewType {
let button = FBLoginButton()
button.permissions = ["public_profile", "email"]
button.delegate = context.coordinator
return button
}
func updateUIView(_ uiView: FBLoginButton, context: Context) { }
func makeCoordinator() -> Coordinator {
return Coordinator()
}
class Coordinator: NSObject, LoginButtonDelegate {
func loginButton(
_ loginButton: FBLoginButton,
didCompleteWith result: LoginManagerLoginResult?,
error: Error?
) {
print("callback triggered")
if result?.token != nil {
print("Logged in")
} else {
print("Failed to login")
}
if let error = error {
print("Login failed with error: \(error.localizedDescription)")
return
}
if let result = result, !result.isCancelled {
if let token = result.token?.tokenString {
print("Access Token: \(token)")
}
}
}
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
print("User logged out")
}
}
}
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]
)
}
}
Мой Info.plist
CFBundleURLTypes
CFBundleURLSchemes
fb
FacebookAppID
FacebookClientToken
FacebookDisplayName
LSApplicationQueriesSchemes
fbapi
fb-messenger-share-api
LSApplicationQueriesSchemes
fbapi
fb-messenger-share-api
fbauth2
fbshareextension
Я вижу кнопку входа в Facebook.
Я могу нажать на эту кнопку.
Оно перенаправляется в приложение Facebook и просит меня «Продолжить как...»
Наконец, после нажатия кнопки «Продолжить» оно перенаправляется обратно на лист/веб-представление, но обратный вызов не вызывается.





Обновление:
Я пробовал добавить этот SceneDelegate, но это не повлияло что угодно:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
openURLContexts URLContexts: Set
) {
print("scene delegate openURLContexts called")
guard let url = URLContexts.first?.url else {
return
}
ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation]
)
}
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = scene as? UIWindowScene else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: FacebookLoginView())
self.window = window
window.makeKeyAndVisible()
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ot-working
Мобильная версия