snibbe
snibbe

Reputation: 2738

How do you access the age_range property of Facebook Graph SDK on iOS

How do you access the age_range Facebook user property (https://developers.facebook.com/docs/graph-api/reference/v2.0/user) via iOS? The other user properties are straightforward (see Fetching user details from Facebook in iOS). E.g. via user.first_name, however, I'm not sure how to inquire and extract the min and max values of this compound property.

Upvotes: 3

Views: 953

Answers (1)

snibbe
snibbe

Reputation: 2738

I believe this is the way to parse the age range:

if (status == FBSessionStateOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
        if (error) {
            SSLog( @"Facebook request failure: %@\n", error.description );
        }
        else
        {
            // Look up age range property and put min and max into string "min-max"
            NSDictionary *ageRangeDict = [user objectForKey:@"age_range"];
            NSString *ageRange = [NSString stringWithFormat:@"%@-%@",
                                  [ageRangeDict objectForKey:@"min"],
                                  [ageRangeDict objectForKey:@"max"]];
        }
    }
     ]
}

Upvotes: 3

Related Questions