How to get the user's country calling code in iOS?

后端 未结 13 2017
终归单人心
终归单人心 2020-12-23 13:24

I am developing an iOS app in which the user enters their mobile number. How do I get their country calling code? For example, if a user is in India, then +91 s

13条回答
  •  遥遥无期
    2020-12-23 13:26

    You can request to this url.
    For get CountryCode or ip, region_name, city, long, lat

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://freegeoip.net/json/"]];
    
    __block NSDictionary *json;
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                               json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                               NSLog(@"Countrycode: %@", json[@"country_code"]);
     }];
    

提交回复
热议问题