Reputation: 43351
Whenever you try and present a TWTweetComposeViewController and a user has no Twitter account added to their device they are prompted to go to the Settings app and add one. Once they are done they have to manually navigate back to the application.
Is there any way for my application to know that they have successfully added an account?
Upvotes: 1
Views: 269
Reputation: 2336
Actually, there is a way to be notified of new accounts while your application is running. ACAccountStore provides a notification ACAccountStoreDidChangeNotification which you can observe for changes using Key-Value Observing.
Upvotes: 3
Reputation: 672
Ah, in that case, you can keep track of how many user accounts they had when they first launched the app, save that to NSUserDefaults. When you're putting up the TWTweetComposeViewController check to see if the number is the same as it was before.
__block BOOL accountSizeChanged = NO;
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted)
{
int oldSize = [[NSUserDefaults standardUserDefaults] integerForKey:@"myKey"];
int newSize = [accountStore accountsWithAccountType:accountType].count;
if(oldSize != newSize)
accountSizeChanged = YES;
[[NSUserDefaults standardUserDefaults] setInteger:newSize forKey:@"myKey"];
}
}];
Upvotes: 1