2
我正在使用Swift 3.0集成Facebook SDK 4.15.1。FBSDKLoginKit在登錄後沒有重定向我的應用並確認頁面
我也跟着鏈接 Getting started with iOS這裏提到的所有步驟,我能夠登錄到Facebook和使使用Safari瀏覽器的授權,但該控件後沒有返回到我的應用程序和一個空白頁所示。但是當我按完成按鈕代理方法didCompleteWith result:
被調用錯誤OAuthException
。此外,OpenURL
方法永遠不會在我的應用程序中被調用。我還徹底驗證了我的屬性列表文件和應用程序ID,在包標識符或應用程序ID中沒有錯誤。
空白頁面未顯示在設備< iOS 9.0中。
任何幫助表示讚賞。
下面是我的登錄代碼和雨燕3.0獲得訪問令牌,
AppDelegate.swift
import UIKit
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}
ViewController.swift
import UIKit
import FBSDKLoginKit
import FBSDKCoreKit
class ViewController: UIViewController, GIDSignInUIDelegate, FBSDKLoginButtonDelegate {
public func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
}
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error == nil {
print("Success")
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id,interested_in,gender,birthday,email,age_range,name,picture.width(480).height(480)"])
graphRequest.start(completionHandler: { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error: \(error)")
}
else
{
print("fetched user: \(result)")
}
})
}else{
print("Failure")
}
}