2013-04-08 30 views
2

用戶後已經允許我的應用程序來訪問他們的Twitter帳戶,他們仍然可以進入設置應用程序,並通過敲擊開關撤銷訪問:如何檢測我的應用無法訪問iOS 6中用戶的Twitter帳戶?

twitter settings app

我的應用程序需要以顯示正確的註銷圖形當這個情況發生時。我可以在iOS 中沒有任何問題,因爲[TWTweetComposeViewController canSendTweet]返回NO當我的應用程序的訪問已被撤銷。然而,即使在訪問已被撤銷後,在iOS ,canSendTweet仍繼續返回YES。所以在iOS 6中我的用戶界面處於錯誤的狀態。有沒有其他方法可以在iOS 6中正確檢測到這一點?

- (id) init 
{ 
    if (self = [super init]) { 
     [[NSNotificationCenter defaultCenter] 
      addObserver:self 
      selector:@selector(accountStatusDidChange:) 
      name:ACAccountStoreDidChangeNotification object:nil]; 
    } 
    return self; 
} 

- (void) accountStatusDidChange:(NSNotification *)notification 
{ 
    if ([TWTweetComposeViewController canSendTweet]) { 
     NSLog(@"app can still access Twitter account in iOS 5"); 
     NSLog(@"always hits this path in iOS 6"); 
    } else { 
     NSLog(@"app permission removed by user in iOS 5"); 
    } 
} 

順便說一句,關於canSendTweet的文檔是錯誤的。關閉後,Twitter將無法再使用。

返回您是否可以發送Twitter請求。

是,如果Twitter 可以訪問並且至少建立了一個帳戶; 否則否。可用性

Available in iOS 5.0 and later. 

宣佈TWTweetComposeViewController.h

回答

1

對於iOS 6,您需要使用Social.framework,並且可以檢查[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]

+0

我剛試過。它撤銷我的應用程序的訪問權後也返回true。 – Pwner 2013-04-08 04:56:54

+0

經過進一步調查,當用戶從設置應用程序中刪除了所有他們的Twitter帳戶時,「isAvailableForServiceType」僅返回false。所以這似乎與撤銷對單個應用程序的訪問無關。 – Pwner 2013-04-08 05:16:34

+1

對我而言根本不起作用 - 在iPad 6.1模擬器中始終返回true。 – 2013-06-07 04:01:14

0

這個問題已經在這裏得到解答https://stackoverflow.com/a/12679828 答案基本上說這是最好的檢查方法。

[self.accountStore requestAccessToAccountsWithType:accountType options:nil 
               completion:^(BOOL granted, NSError *error) 
     { 
      if (granted == YES) { "continue" } 

      else { 
       if ([error code] == 6) { 
        //No accounts defined 
       } 
       else if (error == nil) { 
        //Your permissions are revoked 
       } 
      } 
+0

您應該使用[ACErrorCode枚舉](http://developer.apple.com/library/ios/documentation/Accounts/Reference/AccountsConstantsRef/Reference/reference.html),而不是硬代碼6。 – Joel 2013-08-15 01:35:42

2

在iOS 8中,確定應用程序是否有權訪問用戶的Twitter帳戶變得非常容易。

斯威夫特

ACAccountStore().accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter).accessGranted 

Objective-C的

[[[[ACAccountStore alloc] init] accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter] accessGranted] 

這將返回一個BOOL,告訴您該用戶是否訪問了與否。

相關問題