Objective c 在与iOS5中的警报进行Twitter授权对话之后
我使用ios5twitterapi获得用户使用其Twitter帐户的权限。这会打开一个对话框,他们可以从中选择对应用程序给予或拒绝许可。如果用户接受但没有在iPhone上设置Twitter帐户,我希望能够打开一个警报,但是由于已经打开了一个对话,此时打开警报失败。如何在Twitter权限对话框被取消后立即添加警报Objective c 在与iOS5中的警报进行Twitter授权对话之后,objective-c,ios5,twitter,alert,Objective C,Ios5,Twitter,Alert,我使用ios5twitterapi获得用户使用其Twitter帐户的权限。这会打开一个对话框,他们可以从中选择对应用程序给予或拒绝许可。如果用户接受但没有在iPhone上设置Twitter帐户,我希望能够打开一个警报,但是由于已经打开了一个对话,此时打开警报失败。如何在Twitter权限对话框被取消后立即添加警报 - (IBAction)logInToTwitter:(id)sender { // First, we need to obtain the account instanc
- (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
}
}
}];
}
这在显示警报视图时确实会导致错误。实现这一点的方法是创建一个单独的函数
- (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];
}
}];
}您所说的“此时打开警报失败”到底是什么意思。应用程序崩溃了吗?还是根本没有警报?如果应用程序未崩溃且您无法看到警报,您确定警报不存在吗?