我使用facebook應用程序創建了一個登錄。起初,我去我的個人資料,我創建了應用程序ID,我添加了捆綁標識符。所以,只要我複製並過去到在facebook上創建的具有應用ID和分組標識符的info.plist
。然後我添加了FBSDKCoreKit.framework
和FBSDKLoginKit.framework
。我添加了一些代碼。問題是,Facebook登錄成功。但是,當我按下按鈕時,錯誤被打印出來,並且FBSDKLoginButtonDelegate
函數沒有被調用。我的系統是Lenovo B460e上的Hackintosh Yosemite。請參閱代碼中的單行註釋。提前致謝。如何在swift 2.0中使用facebook登錄
錯誤:
2016年8月17日19:51:40.736的Facebook [925:34154] -canOpenURL:失敗URL: 「fbauth2:/」 - 錯誤: 「(空)」 2016年8月17日19:51:40.808的Facebook [925:34154] -canOpenURL:失敗的URL: 「fbauth2:/」 - 錯誤: 「(空)」
代碼,我嘗試
info.plist
這是我AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
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, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationWillResignActive(application: UIApplication) {
}
func applicationDidEnterBackground(application: UIApplication) {
}
func applicationWillEnterForeground(application: UIApplication) {
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
func applicationWillTerminate(application: UIApplication) {
}
}
這是我的看法Controller.swift
import UIKit
class ViewController: UIViewController,FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton: FBSDKLoginButton = FBSDKLoginButton()
loginButton.center = self.view.center
self.view!.addSubview(loginButton)
if (FBSDKAccessToken.currentAccessToken() != nil) {
print("Hello World!")
self.fetchProfile() //This function called and name,Id printed when the application opens initially that already logged in.
}
}
func fetchProfile()
{
print("Profile Fetched success fully")
let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id,name"], tokenString: "accessToken.tokenString", version: nil, HTTPMethod: "GET")
req.startWithCompletionHandler({ (connection, result, error : NSError!) -> Void in
if(error == nil)
{
print("result \(result)")
}
else
{
print("error \(error)")
}
})
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
print("Hola") //This function not called when got name and ID
}
func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
print("Hello") //This function not called when i log in
return true
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
print("Ni Hao") //This function not called when i log out
}
是的兄弟。那麼有錯誤的兄弟。另外'FBSDKLoginButtonDelegate'函數沒有被調用。我的包標識符未在Apple中註冊。這是造成這個問題嗎? –
嘗試添加此行後,您創建您的登錄按鈕:loginButton.delegate = self –
哇一流的兄弟! 'FBSDKLoginButtonDelegate'函數在添加'loginButton.delegate = self'後工作。所有功能都起作用(提取電子郵件,朋友,身份證,姓名)。但仍然有錯誤發生。 –