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?