iOS:ACAccountTypeIdentifierFacebook的用户全名 [英] iOS: user's full name for an ACAccountTypeIdentifierFacebook

查看:113
本文介绍了iOS:ACAccountTypeIdentifierFacebook的用户全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS的Facebook集成,以允许用户使用其Facebook帐户登录.

I'm using the Facebook integration of iOS to allow user to sign in with their Facebook account.

我在获取用户的全名时遇到了问题.

I encountered a problem getting the user's full name.

我正在创建类型为ACAccountTypeIdentifierFacebookACAccount.

经过一番搜索,我发现了这个小片段以获得全名:

After some searching I found out this little snippet to get the full name:

// account is an ACAccount instance
NSDictionary *properties = [account valueForKey:@"properties"];
NSString *fullName = properties[@"fullname"];

我对其进行了测试,并且可以正常工作.它可以在多种设备上使用.

I tested it, and it worked. It worked on several devices.

然后我们将其发送给我们的客户端,他安装了它,但是它不起作用.

Then we've send it to our client, he installed it, and it didn't work.

经过几天的测试,我能够从同事那里得到在iPhone上发生的错误.

After a few days of testing, I was able to get the error happening on an iPhone from a co-worker.

在快速调试会话后,我发现fullname键不存在.相反,还有另外两个键,分别是ACPropertyFullNameACUIAccountSimpleDisplayName.

After a quick debug session, I found out that the fullname key wasn't present. Instead there were two other keys, ACPropertyFullName and ACUIAccountSimpleDisplayName.

现在获取全名的代码是:

Now my code to get the full name is:

NSDictionary *properties = [account valueForKey:@"properties"];
NSString *nameOfUser = properties[@"fullname"];
if (!nameOfUser) {
    nameOfUser = properties[@"ACUIAccountSimpleDisplayName"];
    if (!nameOfUser) {
        nameOfUser = properties[@"ACPropertyFullName"];
    }
}

所以我的问题实际上分为三个部分:

So my question is actually divided in three parts:

  1. 使用uid键是否可能发生相同的事情?如果是,则存在哪些可能的键?

  1. Is it possible for the same thing to happen with the uid key, and If so, what possible keys exist?

还有其他键来获取全名吗?

Is there any other keys to get the full name?

在Twitter上发生相同的事情,还是总是使用相同的密钥?

Does the same thing happens on Twitter, or it always uses the same keys?

谢谢大家.

推荐答案

您在valueForKey:@"properties"调用中正在执行的操作是访问私有财产,这将使您的应用程序被Apple拒绝.

What you're doing there with the valueForKey:@"properties" call is accessing a private property and it will get your app rejected by Apple.

如果您的项目是iOS 7项目,则可以在ACAccount类上使用名为userFullName的新属性.来自ACAccount.h:

If your project is an iOS 7 project, you can use a new property on the ACAccount class called userFullName. From ACAccount.h:

// For accounts that support it (currently only Facebook accounts), you can get the user's full name for display
// purposes without having to talk to the network.
@property (readonly, NS_NONATOMIC_IOSONLY) NSString *userFullName NS_AVAILABLE_IOS(7_0);

或者,您可以使用图形API 来查询当前用户/ios/documentation/Social/Reference/Social_Framework/_index.html"rel =" nofollow>社交框架:

Alternatively, you can use the Graph API to query the current user using the Social framework:

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                     requestMethod:SLRequestMethodGET
                                               URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
                                        parameters:nil];
request.account = account; // This is the account from your code
[request performRequestWithHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    if (error == nil && ((NSHTTPURLResponse *)response).statusCode == 200) {
        NSError *deserializationError;
        NSDictionary *userData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&deserializationError];

        if (userData != nil && deserializationError == nil) {
            NSString *fullName = userData[@"name"];
            NSLog(@"%@", fullName);
        }
    }
}];

这篇关于iOS:ACAccountTypeIdentifierFacebook的用户全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆