Reputation: 41
I am working on an app which access twitter account. I am getting the access to twitter using following function
[self.accountStore requestAccessToAccountsWithType:accountTypeTwitter
withCompletionHandler:^(BOOL granted, NSError *error) {
above function is getting called from app delegate's "applicationDidBecomeActive" function.
This works fine in iOS 6. But in iOS 5, it shows alert as usual asking permission to access the account. When i press "ok" or "don't allow", applicationDidBecomeActive function getting called again. So it acts like a loop and alert keep coming.
Am i doing anything wrong other than calling it from applicationDidBecomeActive ?
Upvotes: 0
Views: 125
Reputation: 9484
requestAccessToAccountsWithType:options:completion:
method is available only in iOS6 and above.
For iOS5 Use:
requestAccessToAccountsWithType:withCompletionHandler:
EDIT::
[account requestAccessToAccountsWithType:accountType
withCompletionHandler:^(BOOL granted, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
//MY CODE
}
else{
// do whatever you want to do when user dont allow the access to the app
}
});
}];
Upvotes: 0
Reputation: 26385
Try to dispatch the completion handler on the main thread. I've got an "issue" on iOS5 where I wanted to display an alert view after login into TW account. On iOS6 everything was fine but on iOS5 it seemed to show the alert view after 5 sec. I've fixed dispatching the alert on main thread.
If in the completion handler you have some UI functionalities, dispatch them on the main thread, because UIKit for the majority isn't thread safe.
Ciao
Upvotes: 1