0

IOS 5.x 使用 TWTweetComposeViewController 类。一切都很好,即使有

 if ( [TWTweetComposeViewController canSendTweet] )

除非用户在 twitter 上撤销对应用程序的访问权限,否则上述情况仍然正确,并且在尝试发送推文时会出现错误消息

Cannot be sent because the connection to Twitter failed.

如果用户转到 SETTINGS / TWITTER / USERNAME,则可以修复此问题

会出现一条消息

The user name of password is incorrect.

如果重新输入密码,应用程序将在 Twitter 上重新进行身份验证,一切正常。

1)有没有办法在程序控制下捕获错误,然后可以通知用户重做设置?

2) 即使应用程序已被撤销,为什么 canSendTweet 是真的?

4

2 回答 2

1

1) 不,因为它是系统级别的问题,所以不是您可以直接从您的应用程序沙箱控制或管理的问题

2) canSendTweet 仅确认在该设备上可以访问 twitter 并且已经设置了一个帐户。它的目的不是确定用户是否允许您访问他们的 Twitter 帐户。

如果您想知道您的应用是否可以访问用户的 twitter,您应该使用:

- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType 
                  withCompletionHandler:(ACAccountStoreRequestAccessCompletionHandler)handler;

位于账户框架中

#import <Accounts/Accounts.h>

例如,这是一种方法:

        accountStore = [[ACAccountStore alloc] init];
        twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[accountStore requestAccessToAccountsWithType:twitterAccountType 
                     withCompletionHandler:^(BOOL granted, NSError *error) {
                         if (!granted) {
                            // Access denied by the user - do what you need to do
                             NSLog(@"Authenticated : User rejected access to his account.");
                         } 
                         else {
                             // Access granted
                             // Do what you want here to send the tweet or whatever
                         } 
                     }];
于 2012-06-26T19:21:15.630 回答
0

将设备的时间和日期设置为当前时间以外的时间也可能导致此问题。在这种情况下,Twitter 将不允许您从设置应用程序进行身份验证,并且它还会导致 TWTweetComposeViewController 失败并显示“连接到 Twitter 失败”错误消息,即使 canSendTweet 返回 true。

于 2013-06-18T22:22:14.350 回答