После диалога авторизации Twitter с предупреждением в iOS5 - PullRequest
2 голосов
/ 29 февраля 2012

Я использую iOS5 Twitter API, чтобы получить разрешение пользователя на использование его учетной записи Twitter. Это открывает диалоговое окно, из которого они могут выбрать, дать или отклонить разрешение для приложения. Я хотел бы иметь возможность открывать оповещение, если пользователь принимает, но не настроил учетную запись Twitter на своем iPhone, однако, поскольку диалог уже открыт, открыть оповещение в этот момент не удается. Как добавить оповещение сразу после закрытия диалога разрешений Twitter?

- (IBAction)logInToTwitter:(id)sender
{
    //  First, we need to obtain the account instance for the user's Twitter account
    ACAccountStore *store = [[ACAccountStore alloc] init];

    ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [store requestAccessToAccountsWithType:twitterAccountType 
                     withCompletionHandler:^(BOOL granted, NSError *error) {
      if (granted) 
      {
        NSArray *twitterAccounts = [[store accountsWithAccountType:twitterAccountType] autorelease];

        if ([twitterAccounts count] > 0) 
        {
           //All good
        }
        else
        {
           //Open Alert
        }

      }
   }];
}

1 Ответ

1 голос
/ 16 марта 2013

Это вызывает ошибку при отображении вида предупреждения.Способ сделать эту работу состоит в том, чтобы создать отдельную функцию.

- (void)noTwitterAccountMessage {
    UIAlertView *alertViewTwitter = [[UIAlertView alloc] initWithTitle:@"No Twitter Accounts"
                                                           message:@"There are no Twitter accounts configured. You can add or create a Twitter account in Settings."
                                                          delegate:nil
                                                 cancelButtonTitle:@"OK"
                                                 otherButtonTitles:nil];

    [alertViewTwitter show];
}

, а затем внутри обратного вызова хранилища учетных записей, вы должны назвать его так:

-(void)requestTwitterAccess
{
    [self.accStore requestAccessToAccountsWithType:self.twitterType
                     withCompletionHandler:^(BOOL granted, NSError *error) {
                         if (!granted) {
                             [self performSelectorOnMainThread:@selector(noTwitterAccountMessage) withObject:self waitUntilDone:NO];
                         }
}];

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...