有没有一种方法可以检查用户是否使用Twitter登录? [英] Is there a way to check if a user is signed in with Twitter?

查看:363
本文介绍了有没有一种方法可以检查用户是否使用Twitter登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本教程

https://parse.com/docs/ios_guide#twitterusers/iOS

对于这个应用程序,我正在执行Twitter交易登录.有一个问题.如果用户未登录Twitter(他们未通过设置登录),则此代码运行时将不显示任何内容:

For this app, I'm doing a sign in with Twitter deal. There's one problem. If a user is not signed into twitter (they didn't sign in from settings), nothing is displayed when this code runs:

[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
    if (!user) {
        NSLog(@"Uh oh. The user cancelled the Twitter login.");
        return;
    } else if (user.isNew) {
        NSLog(@"User signed up and logged in with Twitter!");
    } else {
        NSLog(@"User logged in with Twitter!");
    }    
}];

我想知道是否有一种方法可以检查用户是否通过设置登录,因此我可以设置一条消息,说他们应该通过设置登录.有人知道一种检查方法吗?

I am wondering if there is a way to check if a user is signed in from settings so I can set up a message saying they should sign in from settings. Does anyone know a way to check this?

推荐答案

Swift 4

我正在使用TwitterKit并与cocoapod一起安装 Twitterkit具有用于存储已登录用户会话的sessionstore.

I am using TwitterKit and installed it with cocoapod Twitterkit has sessionstore which stores session for the logged in users.

if TWTRTwitter.sharedInstance().sessionStore.session() != nil {
            print("user signed in with twitter ..")
}

用于从Twitter注销

For logout from twitter

func logoutTwitter() {
        let store = TWTRTwitter.sharedInstance().sessionStore
        if let userID = store.session()?.userID {
            store.logOutUserID(userID)
        }
}

这是获取有关已登录用户的信息的方法

This is how to get information about logged in user

func getTwitterUserInformation() {
    let store = TWTRTwitter.sharedInstance().sessionStore
    if let userID = store.session()?.userID {

        let client = TWTRAPIClient.withCurrentUser()
        client.loadUser(withID: userID) { (user, error) in
            print(user?.name)
            print(user?.screenName)
        }

    }
}

这篇关于有没有一种方法可以检查用户是否使用Twitter登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆