0

这是我的脸书方法:

- (void)getMeFacebook{

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    __block ACAccount *facebookAccount = nil;

    ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions

    NSDictionary *options = @{ACFacebookAppIdKey : @"1405219416361729",

                              ACFacebookPermissionsKey : @[@"email", @"publish_stream"],

                              ACFacebookAudienceKey:ACFacebookAudienceFriends};

    [accountStore requestAccessToAccountsWithType:facebookAccountType

                                          options:options completion:^(BOOL granted, NSError *error)

     {
         if (granted)
         {
             NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

             facebookAccount = [accounts lastObject];

             NSLog(@"Granted!!!");

         }

         else {

             NSLog(@"error.localizedDescription======= %@", error.localizedDescription);

         }

     }];


    NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

    facebookAccount = [accounts lastObject];


    NSLog(@"Break 1");

调试代码时,它从不评估 if(granted),似乎方法 requestAccessToAccountsWithType 的行为不正确。我已经检查了应用程序中的 facebook 设置,但仍然无法正常工作。

对这个问题有任何想法吗?

4

1 回答 1

0

经过几个小时的调试和研究,我找到了解决方案,每次你必须在 Objective-c 中调试方法的块(回调)时,都需要在块内添加额外的中断时间。

问题是同步问题,因为该方法是在 main.m 中调用的,并且UIAlert请求访问 iPhone 中的 facebook 数据的权限从未出现。我将该方法的调用移至 viewDidLoad 并且整个应用程序工作正常!

于 2013-09-11T15:19:05.983 回答