2012-05-24 1 views
1

TWTweetComposeViewController를 시도 할 때마다 사용자가 Twitter 계정을 자신의 장치에 추가하지 않은 경우 설정 앱으로 이동하여 추가 할 것인지 묻는 메시지가 표시됩니다. 작업이 완료되면 수동으로 응용 프로그램으로 다시 이동해야합니다.내 응용 프로그램이 사용자가 Twitter 계정을 추가했는지 알 수있는 방법이 있습니까?

내 응용 프로그램이 계정을 성공적으로 추가했는지 알 수있는 방법이 있습니까?

답변

3

실제로 애플리케이션이 실행되는 동안 새 계정에 대한 알림을받을 수있는 방법이 있습니다. ACAccountStore는 Key-Value Observing을 사용하여 변경 사항을 관찰 할 수있는 알림 ACAccountStoreDidChangeNotification을 제공합니다.

+0

어떻게이 작업을 수행 할 수 있습니까? 나는 [[NSNotificationCenter defaultCenter] addObserver : 셀렉터 : @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

관련 문제