Ios 未设置帐户时的Fabric Twitter登录问题?

Ios 未设置帐户时的Fabric Twitter登录问题?,ios,objective-c,iphone,twitter,twitter-fabric,Ios,Objective C,Iphone,Twitter,Twitter Fabric,我也在使用Twitter的fabric,通过Twitter登录&获取用户的详细信息。我使用下面的代码 [[Twitter sharedInstance] logInWithCompletion:^ (TWTRSession *session, NSError *error) { if (session) { NSLog(@"signed in as %@", [session userID]); } else {

我也在使用Twitter的fabric,通过Twitter登录&获取用户的详细信息。我使用下面的代码

[[Twitter sharedInstance] logInWithCompletion:^
     (TWTRSession *session, NSError *error) {
         if (session) {
             NSLog(@"signed in as %@", [session userID]);
         } else {
             NSLog(@"error: %@", [error localizedDescription]);
         }
     }];
当我在iPhone的设置中配置了twitter帐户,即在iPhone的twitter应用程序中添加用户名和密码时,工作正常。 但是如果这是空的&没有配置twitter帐户,我无法登录&将得到错误请求失败:未经授权(401)

我是否可以要求用户输入其用户名和密码

提前谢谢


-Aakil

您可以这样检查:

if (![TWTweetComposeViewController canSendTweet]) {
    NSLog(@"No Twitter Accounts");
}
如果您不想进行设置,则需要使用fabric方式登录。在他们使用按钮的文档中,我不知道您的应用程序的生命周期,但此时您可以在某处显示此按钮,并要求他们登录。以下是文档中的一些代码:

TWTRLogInButton* logInButton =  [TWTRLogInButton
                                     buttonWithLogInCompletion:
                                     ^(TWTRSession* session, NSError* error) {
    if (session) {
         NSLog(@"signed in as %@", [session userName]);
    } else {
         NSLog(@"error: %@", [error localizedDescription]);
    }
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton]; 

希望能有帮助。

好吧,我为碰巧找到这个的人想出了这个办法。 转到youdeveloper.twitter应用程序(他们的网站)

在应用程序设置中添加回调URL。(不管是什么)


该按钮现在可以工作。

是的,我知道,但是如果我希望用户登录而不在“设置”中配置帐户,该怎么办?@gyer如果您的设置中没有twitter帐户,则该按钮不起作用。。。在我的例子中:关闭网络,然后调用logInWithCompletion:method登录。它将显示一个没有关闭按钮的空白UI。调试视图层次结构时,我发现keyWindow的rootViewController正在替换一个空视图。因此,我必须重置我的rootViewController。[UIApplication sharedApplication].keyWindow.rootViewController=[MyViewController新建];