I\'m developing a Facebook application using their Graph API. I have previously developed an app using the deprecated REST API.
I\'ve come across a problem in that
You should try like this:
/* make the API call */
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary *user,
NSError *error)
{
if (!error)
{
self.countryName = [[[user objectForKey:@"location"] valueForKey:@"name"] componentsSeparatedByString:@", "][1];
self.countryCode = [self getCountryCodeForCountry:STUser.countryName];
}
}];
-(NSString *)getCountryCodeForCountry:(NSString*)country
{
NSMutableArray *countries = [self getCountries];
NSArray *countryCodes = [NSLocale ISOCountryCodes];
NSDictionary *codeForCountryDictionary = [[NSDictionary alloc] initWithObjects:countryCodes forKeys:countries];
return [codeForCountryDictionary objectForKey:country];
}
+(NSMutableArray *)getCountries
{
NSMutableArray *countries = [NSMutableArray array];
NSArray *countryCodes = [NSLocale ISOCountryCodes];
countries = [NSMutableArray arrayWithCapacity:[countryCodes count]];
for (NSString *countryCode in countryCodes)
{
NSString *identifier = [NSLocale localeIdentifierFromComponents:[NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];
[countries addObject: country];
}
return countries;
}