如何检查用户是否在Pinterest IOS SDK中获得授权?

时间:2016-01-26 23:36:22

标签: ios swift pinterest

在我使用Parse的其他应用中,我检查currentUser是否为零,如果没有超过LogInViewController。使用Pinterest SDK,我无法在文档中的任何位置找到currentUser

最好的结构方式是什么,如果用户已经授权,performSegueWIthIdentifier,如果不显示此LogInViewController?我正在考虑将用户的名字保存到NSUserDefaults,然后调用PDClient.sharedInstance().getUser(nameSavedToNSUD),如果成功执行了segue但是看起来有点像黑客并且必须有更好的方法?

import UIKit

class LogInViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }


    @IBAction func didPressLogInButton(sender: UIButton) {


        let permission = [PDKClientReadPublicPermissions,
            PDKClientWritePublicPermissions,
            PDKClientReadPrivatePermissions,
            PDKClientWritePrivatePermissions,
            PDKClientReadRelationshipsPermissions,
            PDKClientWriteRelationshipsPermissions]
        PDKClient.sharedInstance().authenticateWithPermissions(permission,
            withSuccess: { (responseObject :PDKResponseObject!) -> Void in


                    self.performSegueWithIdentifier("showBoards", sender: self)



            }) { (err :NSError!) -> Void in
                print("error NSError: \(err)")
        }





    }


}

1 个答案:

答案 0 :(得分:1)

Pinterest SDK有一个`silentntlyAuthenticatedWithSuccess'这里效果很好的方法:

PDKClient.sharedInstance().silentlyAuthenticateWithSuccess( { (responseObject :PDKResponseObject!) -> Void in


            self.performSegueWithIdentifier("showBoards", sender: self)



            }) { (err :NSError!) -> Void in
                print("error NSError: \(err)")
        }