1

am developing an app (iOS5+) where I am posting on Twitter. I would like to check if the system has a Twitter account configured, so that they may log in through Twitter if an account is available otherwise they will be presented a webview to log in (using unofficial-twitter-sdk) or they will be sent to Settings to add a Twitter account to the system (but I don't like this way since you cannot get back the user to the app).

The only problem with this approach is that on the simulator I can check how many accounts there are using

ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Get the list of Twitter accounts and checks
NSArray *accountsArray = [_accountStore accountsWithAccountType:twitterAccountType];

while the same code does not work on the real devices, reporting always that the array is empty (since it returns only the accounts which gave already permission to the app to use Twitter).

The second approach would be using the completion handler of the -ACAccountStore requestAccessToAccountsWithType:withCompletionHandler: method, in particular

// We can user the twitter iOS accounts, but we use a custom view to post the content
[_accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted)
{
// POST
}
else
{
// error?
}

but in the second case the error is always nil, in any of the following cases: 1. user did not grant the permission to use the system account 2. there are no accounts available

So basically I cannot discriminate between the two cases in any way, therefore I don't know if I should present the user with a view to log in (second case) or just fail because they did not want to log in.

Any insight? Is there a workaround?

Fr4ncis
  • 1,387
  • 1
  • 11
  • 23
  • see my answer http://stackoverflow.com/questions/18459252/how-to-post-on-twitter-by-hiding-slcomposeviewcontroller-tweetsheettweet-instan/18460093#18460093 – Shankar BS Aug 28 '13 at 11:22
  • @Shan thank you but the "You have no Twitter account" never gets called, because in case of no accounts granted==NO anyway. So basically as far as I noticed in both cases (1. rejected to give access 2. no accounts available) granted==NO, error==nil and number of accounts is 0 anyway. – Fr4ncis Aug 28 '13 at 12:36
  • if u use twitter framework see this answer it will ask user to set account by launching settings app see this answer might u get answer http://stackoverflow.com/questions/13946062/twitter-framework-for-ios6-how-to-login-through-settings-from-app – Shankar BS Aug 28 '13 at 13:13
  • It is better to create account in device then only publish the post – Shankar BS Aug 28 '13 at 13:15

0 Answers0