我目前正在使用下面的代码通过自定义 Sprite 节点按钮登录 facebook:
func runLoginForFacebook() {
print("logging in with facebook...")
print("FACEBOOK CURRENT TOKEN ---->\(FBSDKAccessToken.current())")
let login = FBSDKLoginManager()
let viewController = UIApplication.shared.keyWindow?.rootViewController
login.logIn(withReadPermissions: ["public_profile"], from: viewController, handler: { result, error in
if error != nil {
print("Process error \(error!.localizedDescription)")
} else if result?.isCancelled != nil {
print("Cancelled \(error?.localizedDescription)")
} else {
print("Logged in")
signIntoFirebase()
}
})
}
现在这允许我登录并点击继续按钮,因此屏幕被关闭,但它总是返回 isCanceled 为是而不是登录。
我在整个网站上搜索了答案,他们都说应用委托(delegate)是问题所在,我的应用委托(delegate)似乎没问题:
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
// Add any custom logic here.
return handled
}
下一个解决方案是,我在 facebook 的开发人员门户中的应用程序中没有任何测试用户,我检查过,但情况并非如此,我拥有与用于作为测试用户/管理员登录的相同帐户应用程序。
我还检查了我的 info.plist 文件,一切似乎都很好(见下文。出于隐私原因,我在姓名和号码中加入了 XXXX 号码检查正常并且与开发人员门户 ID)
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb4961923108XXXXX</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>496192XXXXXXXX</string>
<key>FacebookDisplayName</key>
<string>NaXXX</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
有人可以帮助我吗?任何想法将不胜感激,因为我已经在这里工作了一天,但我无法弄清楚。
最佳答案
你正在检查 if result?.isCancelled
不是 nil,所以如果你有一个结果,它永远是 true 或 false,永远不会是 nil。试试下面的代码(注意这没有经过测试,所以如果我搞砸了语法,请随时用正确的代码编辑我的答案)
func runLoginForFacebook() {
print("logging in with facebook...")
print("FACEBOOK CURRENT TOKEN ---->\(FBSDKAccessToken.current())")
let login = FBSDKLoginManager()
let viewController = UIApplication.shared.keyWindow?.rootViewController
login.logIn(withReadPermissions: ["public_profile"], from: viewController, handler: { result, error in
guard let result = result else {
print("No result found")
}
if result.isCancelled {
print("Cancelled \(error?.localizedDescription)")
} else if let error = error {
print("Process error \(error.localizedDescription)")
} else {
print("Logged in")
signIntoFirebase()
}
})
}
关于ios - spritekit 中的 Facebook 登录总是返回已取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55379485/