简体   繁体   English

iOS Swift和Facebook SDK

[英]IOS Swift and Facebook SDK

Let me apologize first, just learning swift, so I am not 100% on what I am doing. 首先让我道歉,只是学习敏捷,所以我不是100%地在做自己的事情。 I have found many tutorials on integrating a facebook login in swift and have what appears to be working in the app, but it seems my delegates are never getting called. 我发现了许多关于快速集成Facebook登录的教程,并且在该应用程序中似乎可以正常运行,但是似乎从未有人致电我的代表。 What I expect to happen is when a user logins 2 things should happen. 我希望发生的事情是用户登录时发生2件事。

1) The login button for facebook should change to a logout button. 1)Facebook的登录按钮应更改为注销按钮。
2) A console command should print that I logged in, and ultimately user information. 2)控制台命令应打印我登录的信息,并最终显示用户信息。

ViewController Class is : ViewController类是

class ViewController: UIViewController,FBLoginViewDelegate {

    @IBOutlet var fbLoginView : FBLoginView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]
    }

    // Facebook Delegate Methods

    func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
        println("User Logged In")
        println("This is where you perform a segue.")
    }

    func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
        println("User Name: \(user.name)")
    }

    func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
        println("User Logged Out")
    }

    func loginView(loginView : FBLoginView!, handleError:NSError) {
        println("Error: \(handleError.localizedDescription)")
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

AppDelegate sections are: AppDelegate部分是:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    FBLoginView.self
    FBProfilePictureView.self

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool {

        var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
        return wasHandled

    }

    return true
}

As you can see, most of this is straight from the tutorials but is not working correctly. 如您所见,大多数内容直接来自于教程,但无法正常工作。 I've got my info.plist configured, and the FBLoginView appears and goes thru the entire authentication, but nothing is printed to console and the button doesn't change. 我已经配置好了info.plist,并且出现了FBLoginView并通过了整个身份验证,但是没有打印任何内容到控制台,并且按钮没有改变。
When I try to click it again, I get app already authorized, which should mean that the auth was successful, but nothing got triggered back in my app. 当我再次尝试单击它时,我已经获得了应用程序的授权,这应该意味着身份验证已成功完成,但是没有任何触发。

I feel confident that something is probably wrong with my appdelegate but being new to swift, I have no clue what.. 我确信自己的appdelegate可能出了点问题,但很快就陌生了,我不知道该怎么办。

Facebook as changed SDk. Facebook已更改为SDk。 Please find the latest solution here 请在这里找到最新的解决方案

http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/ http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/

I would like to suggest you the cheking of these steps: -in your VC class, import FacebookSDK statement and FBLoginViewDelegate ? 我想建议您使用这些步骤:-在您的VC类中,导入FacebookSDK语句和FBLoginViewDelegate? - your outlet should be: -您的出口应为:

//FB outlet
@IBOutlet var fbLoginView: FBLoginView

- in your AppDelegate.swift, also imported the FacebookSDK ? -在您的AppDelegate.swift中,还导入了FacebookSDK吗? - you have a func in a func in your AppDelegate.swift.It should be: -在AppDelegate.swift中的func中有一个func,它应该是:

import FacebookSDK

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @UIApplicationMain类AppDelegate:UIResponder,UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    //FB implementation
    FBLoginView.self
    FBProfilePictureView.self


    return true
}

//FB Method handles what happens after authentication
func application (application:UIApplication, openURL url:NSURL, sourceApplication:NSString?, annotation:AnyObject) -> Bool {
    //test var
    var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
// attempt to extract a token from the url
return wasHandled

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM