2013-10-31 1 views
1

iOS의 Facebook 통합을 사용하여 사용자가 Facebook 계정으로 로그인 할 수 있습니다.iOS : ACAccountTypeIdentifierFacebook에 대한 사용자의 전체 이름

사용자의 성명을 가져 오는 동안 문제가 발생했습니다.

ACAccountACAccountTypeIdentifierFacebook입니다.

내가 이름을 얻기 위해이 작은 조각을 발견 된 일부 검색 후 :

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

나는 그것을 테스트, 그것은했다. 여러 장치에서 작동했습니다.

그런 다음 고객에게 보내고 설치했으나 작동하지 않았습니다.

며칠 동안 테스트를 마치면 동료와 iPhone에서 오류가 발생했습니다.

빠른 디버그 세션 후 fullname 키가 없음을 알았습니다. 대신 두 개의 다른 키, ACPropertyFullNameACUIAccountSimpleDisplayName이 있습니다.

지금 전체 이름을 얻을 내 코드는 다음과 같습니다 그래서 제 질문은 실제로 세 부분으로 나누어 져

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

: 같은 일이 uid으로 발생하는

  1. 이 가능 키, 그리고 그렇다면 가능한 키는 무엇입니까?

  2. 전체 이름을 얻는 데 필요한 다른 키가 있습니까?

  3. Twitter에서 똑같은 일이 발생합니까, 아니면 항상 같은 키를 사용합니까?

고마워요.

답변

1

valueForKey:@"properties" 호출로 개인 재산에 액세스하고 Apple에서 귀하의 앱을 거부하게됩니다.

프로젝트가 iOS 7 프로젝트 인 경우 이라는 ACAccount 클래스의 새 속성을 사용할 수 있습니다. 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); 

, 당신은 Social framework 사용하여 current user를 조회 할 Graph API를 사용할 수 있습니다

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); 
     } 
    } 
}]; 
+0

감사합니다, 그것은 일) – rtiago42

관련 문제