0

我需要在两个标签中显示 facebook 和 twitter 个人资料名称

这些配置文件名称应该来自设置页面设​​置

iif 在设置中是否有任何 facebook 帐户设置我必须在我的应用程序中获取用户名并拒绝它对于 twitter 设置同样的事情以及如何实现它。

谢谢,

签入设置

在此处输入图像描述

![在此处输入图像描述][2]

![在此处输入图像描述][3]

4

1 回答 1

0

使用社交框架,使用您获取帐户的详细信息 -

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

ACAccountType *twitterAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error)
 {
     if(granted)
     {
         NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];
         NSLog(@"twitterAccounts %@", twitterAccounts);
     }
 }];


ACAccountType *facebookAccountType =  [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
//your app id is the key, i have used "Demo".
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:@"Demo", ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];

[accountStore requestAccessToAccountsWithType:facebookAccountType options:dictFB completion:
 ^(BOOL granted, NSError *e) {
     if (granted) {
         NSArray *facebookAccounts = [accountStore accountsWithAccountType:facebookAccountType];
         // fb accounts
         NSLog(@"facebook accounts =%@", facebookAccounts);
     } else {
         //Error
         NSLog(@"error getting permission %@",e);
     }
 }];

同样,如果配置了 1 个以上的帐户,您可以遍历这些帐户并获取信息。

编辑 - 什么是 ACFacebookAppIdKey、ACFacebookPermissionsKey?

ACCOUNTS_EXTERN NSString * const ACFacebookAppIdKey NS_AVAILABLE(NA, 6_0);            // Your    Facebook App ID, as it appears on the Facebook website.
ACCOUNTS_EXTERN NSString * const ACFacebookPermissionsKey NS_AVAILABLE(NA, 6_0);      // An array of of the permissions you're requesting.
于 2014-07-15T07:43:03.460 回答