2012-05-24 35 views

回答

3

其实,有你的应用程序运行时被通知的新帐户的方式。 ACAccountStore提供通知ACAccountStoreDidChangeNotification,你可以观察使用键 - 值观察的变化。

+0

这怎么办?我试过[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accountChanged :) name:ACAccountStoreDidChangeNotification object:nil];但我似乎无法从我的方法accountChanged得到一些东西。有什么我在这里失踪?我在viewDidLoad中添加了观察者。 –

1

啊,在这种情况下,你可以跟踪他们有多少用户帐户有当他们第一次推出的应用程序,从而节省NSUserDefaults的到。当你打开TWTweetComposeViewController时,检查数字是否与以前相同。

__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"]; 
    } 
}]; 
+0

这只会告诉我他们是否有一个或多个帐户。我想知道帐号数量是否发生了变化。如果他们已经拥有一个账户并添加了另一个账户呢 – Undistraction

+0

我编辑了我的第一个答案,以适应此。 – mergesort

+0

为你做了那个工作1ndivisible? – mergesort

相关问题