【问题标题】:requestAccessToAccountsWithType completion not being called未调用 requestAccessToAccountsWithType 完成
【发布时间】:2013-11-21 01:49:22
【问题描述】:

当我运行 [_accountStore requestAccessToAccountsWithType: ...] 时,我没有得到任何响应。我的完成处理程序没有被调用。不过我确实可以访问 Twitter。

    //  Step 0: Check that the user has local Twitter accounts
    if ([SLComposeViewController
     isAvailableForServiceType:SLServiceTypeTwitter]) {
        NSLog(@"OH YES!!!");
        //  Step 1:  Obtain access to the user's Twitter accounts
        ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter];
        NSLog(@"OH YES!!!");

        [_accountStore requestAccessToAccountsWithType:twitterAccountType options:nil
                                       completion:^(BOOL granted, NSError *error)
        {
            NSLog(@"Im in!");
            if (granted == YES)
            {
                NSArray *arrayOfAccounts = [_accountStore
                                            accountsWithAccountType:twitterAccountType];

                if ([arrayOfAccounts count] > 0)
                {
                    ACAccount *twitterAccount = [arrayOfAccounts lastObject];

                    NSLog(@"%@", twitterAccount.userFullName);
                    NSLog(@"%@", twitterAccount.username);
                    NSLog(@"%@", twitterAccount.credential);
                    NSLog(@"%@", twitterAccount.identifier);

                }
            }else{
                NSLog(@"Failed muahahaha");
            }
        }];
    }

为什么会这样?

【问题讨论】:

    标签: objective-c twitter accounts social-framework


    【解决方案1】:

    使 shure _accountStore 被初始化,例如使用

    _accountStore = [[ACAccountStore alloc] init];
    

    【讨论】:

    • 我昨天发现了我的问题。我确实初始化了它,但是在 viewDidLoad 中。直到我把它移到我的功能中,我才认为这是一个问题。出于好奇,为什么当我在 viewDidLoad 中初始化 _accountStore 时它不起作用?
    • 另外,我忘了补充一点,我显然阻止了我的应用程序使用 twitter。手滑,哈哈,一旦我重置了设备上的设置并更改了那行代码,一切都很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2011-04-06
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多