3

I understand how to ask for Twitter access using:

requestAccessToAccountsWithType:withCompletionHandler:

But this pops a dialogue if the app isn't authorised. How can I silently check to see if the app is authorised?

I can check the number of accounts using:

 NSArray *twitterAccounts = [store accountsWithAccountType:twitterAccountType];

But I will get an empty array back if I the app is not authorized AND if there are no accounts available. I can't see a way of finding out which of these is the case.

To clarify I need to tell the difference between the following cases:

  1. A user has not granted the application permission to use Twitter.
  2. A user has granted permission but has not set up any Twitter accounts.

There is also TWTweetComposeViewController canSendTweet which will return true if The app is authorised AND there is at least one account setup. However, again this doesn't give me the ability to tell the difference between the two cases if it returns false.

Undistraction
  • 42,754
  • 56
  • 195
  • 331
  • I don't get why would one need that? Either way, you can't get any access to user's twitter account... hence `canSendTweet` – marko Jul 12 '12 at 20:39
  • @soemarko ridwan I have a 'Share With Twitter' button in a landscape view. The button has a second label. I would like to inform the user about the Twitter status using this label. I would like to be able to say either 'No Twitter Accounts available' or 'Unauthorised'. I know I can't get access to a user's account without their permission. At no point do I say that is what I want. – Undistraction Jul 12 '12 at 21:44
  • It appears that the second scenario, "user has granted permission but has not set up any Twitter accounts", can't happen. At least on iOS 6, if a user has no Twitter accounts configured then iOS denies access, i.e. in the completion block for `requestAccessToAccountsWithType:withCompletionHandler:`, `granted` is always set to `NO`. – Simon Whitaker Oct 30 '12 at 12:42

1 Answers1

7

It looks like there's an accessGranted property of each account type you can check to see if you've been authorized to use it: http://developer.apple.com/library/ios/#DOCUMENTATION/Accounts/Reference/ACAccountTypeClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40011022

So I'd check that to see if you've been authorized first, and if so, then pull the list of twitter accounts and see if there's anything in the array.

Jay Neely
  • 284
  • 1
  • 3
  • 10
  • Ah. Some place I didn't look. Thanks a lot. – Undistraction Jul 14 '12 at 17:43
  • Also worth noting that it seems ACAccountType::accessGranted always returns false in Simulator; even if a Twitter account is set, this property will always render false on an ACAccount type of ACAccountTypeIdentifierTwitter. – Undistraction Jul 16 '12 at 17:16
  • Fwiw this is a very buggy API. It often returns false despite the app being authorised and even though it will happily let you access Twitter. – Undistraction Jul 31 '12 at 20:37