无法从Facebook IOS请求中调用UIView

时间:2013-02-21 15:09:55

标签: ios facebook ios5 ios6

我在IOS6中进行了以下设置,通过我的应用程序连接到Facebook。

self.accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookAccountType = [self.accountStore
                                      accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Specify App ID and permissions
NSDictionary *options = @{
                          ACFacebookAppIdKey: @"xxxxxxxxxxxxx",
                          ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
                          ACFacebookAudienceKey: ACFacebookAudienceFriends
                          };

[accountStore requestAccessToAccountsWithType:facebookAccountType
                                      options:options completion:^(BOOL granted, NSError *e) {
                                          if (granted) {
                                              NSArray *accounts = [self.accountStore
                                                                   accountsWithAccountType:facebookAccountType];
                                              self.facebookAccount = [accounts lastObject];
                                              NSLog(@"Logged In :: %@",self.facebookAccount);

                                              [self uploadVideo];

                                          }
                                          else
                                          {
                                              NSLog(@"Logged In Fail");
                                          }
                                      }];

问题是我想以UIAlertView的形式提供一些反馈,其中else语句是。当我添加以下内容时,应用程序崩溃了EXC_BAD_ACCESS

UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: @"Unable To Connect With Facebook"
                      message: @"xxxxxxxxxxxxx."
                      delegate: nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil];
[alert show];

如果我只是调用一个没有警报视图的方法,那似乎工作正常。有人有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你确定完成块在主线程上吗?

尝试将警报视图代码包装到主线程的调度中。

dispatch_async(dispatch_get_main_queue(), ^(void) {

});