在 iOS 上使用 Twitter 登录 [英] Login with Twitter on iOS

查看:142
本文介绍了在 iOS 上使用 Twitter 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS 上登录 Twitter 时遇到问题.如果用户在设置"应用程序中设置了帐户,则会出现以下错误:

<块引用>

[TwitterKit] 确实遇到错误消息用户的系统帐户凭据无效.":错误域=TWTRLogInErrorDomain 代码=7系统帐户凭据不再有效,需要在设置应用程序中更新." UserInfo={NSLocalizedDescription=The系统帐户凭据不再有效,需要在设置应用程序中更新. NSLocalizedRecoverySuggestion=用户已被提示访问设置"应用.}

并且凭据有效,我会仔细检查.如果设置应用程序中没有帐户,我的登录会按预期进行.我调用的方法是:

Twitter.sharedInstance().logInWithCompletion {(session, error) ->作废

解决方案

我觉得下面的方法应该也能用.

Twitter.sharedInstance().logIn(withCompletion: {(session: TWTRSession, error: Error) -> Void in如果会话{print("@\(session.userName()) 已登录!(\(session.userID()))")}别的 {打印(错误:\(错误!.localizedDescription)")}})

<块引用>

它需要来自设置 Twitter 应用的帐户凭据.

更多内容:- AppDelegate.m

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]) ->布尔{//推特Twitter.sharedInstance().start(with: kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)Fabric.with([Twitter.sharedInstance()])返回真}

  • 信息.plist

I have a problem with twitter login on iOS. If the user has account set in Settings application, I get the following error:

[TwitterKit] did encounter error with message "User's system account credentials are invalid.": Error Domain=TWTRLogInErrorDomain Code=7 "The system account credentials are no longer valid and will need to be updated in the Settings app." UserInfo={NSLocalizedDescription=The system account credentials are no longer valid and will need to be updated in the Settings app., NSLocalizedRecoverySuggestion=The user has been prompted to visit the Settings app.}

And the credentials are valid, I double check that. If there are no account in Settings app, my login goes as expected. The method I call is:

Twitter.sharedInstance().logInWithCompletion {(session, error) -> Void in

解决方案

I think the following method should also work.

Twitter.sharedInstance().logIn(withCompletion: {(session: TWTRSession, error: Error) -> Void in
    if session {
        print("@\(session.userName()) logged in! (\(session.userID()))")
    }
    else {
        print("error: \(error!.localizedDescription)")
    }
})

It takes the account credentials from the Settings Twitter app.

More to look into: - AppDelegate.m

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]) -> Bool {
    //Twitter
    Twitter.sharedInstance().start(with: kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)
    Fabric.with([Twitter.sharedInstance()])
    return true
}

  • Info.plist

这篇关于在 iOS 上使用 Twitter 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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