2012-03-20 21 views
0

使用TWTweetComposeViewController類的IOS 5.x。一切都很好,甚至與TWTweetComposeViewController cansendtweet即使當用戶在twitter中撤銷應用程序時也是如此

if ([TWTweetComposeViewController canSendTweet]) 

除非用戶撤銷對Twitter的應用程序訪問,那麼上面仍然是正確的,並試圖發送的tweet顯示一條錯誤消息

Cannot be sent because the connection to Twitter failed. 

這時候如果用戶去設置/ TWITTER/USERNAME可以固定

的消息會想出

The user name of password is incorrect. 

如果密碼被重新輸入,應用程序將在Twitter上重新驗證,並且一切都很好。

1)是否有無法捕捉程序控制下的錯誤,然後可以通知用戶重做設置?

2)即使應用程序被撤銷,canSendTweet的真實性如何?

回答

1

1)沒有,因爲它是一個系統級問題,所以不是你可以控制或直接從您的管理應用沙箱

2)canSendTweet只是證實,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 
         } 
        }]; 
0

此問題也可能是由於您的設備的時間和日期設置爲時間ot她比當前時間。在這種情況下,Twitter不會允許您通過設置應用程序進行身份驗證,而且即使canSendTweet返回true,也會導致TWTweetComposeViewController失敗,並顯示「連接失敗」錯誤消息。

相關問題