iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在iOS中使用Twitter Framework处理Twitter大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道要在iOS 5中使用twitter框架访问已配置的Twitter帐户,可以执行以下操作:

ACAccountStore *t_account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypEIDentifier:ACAccountTypEIDentifierTwitter];
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted,NSError *error) {
    if (granted == YES) {
    }
}

但问题是我不需要一个完整的帐户,如果他在Twitter帐户上配置了任何帐户,我只想要推特名称.那么,有没有办法从框架(而不是完整的帐户)获得Twitter句柄而不询问任何用户权限?

解决方法

如果用户未授予访问这些帐户的权限,您将无法访问任何帐户.只需在新项目中的应用程序委托中尝试以下内容,即可知道该应用程序未获得访问Twitter帐户的权限.当然,请确保您在设备或模拟器中至少有一个Twitter帐户,并在项目和应用程序委托中导入帐户框架.此外,您假设用户只有一个Twitter帐户.最适合用户可能拥有多个帐户的情况的代码.

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

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypEIDentifier:ACAccountTypEIDentifierTwitter];

    NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

    for (ACAccount *account in accountsArray ) {
        NSLog(@"Account name: %@",account.userName);
    }

    NSLog(@"Accounts array: %d",accountsArray.count);

现在更改代码以在用户授予权限时返回结果:

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

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypEIDentifier:ACAccountTypEIDentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted,NSError *error) {

    if(granted) {

        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        for (ACAccount *account in accountsArray ) {
            NSLog(@"Account name: %@",account.userName);
        }

        NSLog(@"Accounts array: %d",accountsArray.count);
    }
}];

所以我想简短的回答是,苹果要求用户授予用户帐户权限是有原因的.如果未授予该访问权限,则不会获得任何数据.

大佬总结

以上是大佬教程为你收集整理的在iOS中使用Twitter Framework处理Twitter全部内容,希望文章能够帮你解决在iOS中使用Twitter Framework处理Twitter所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。