How to get current country without using “LocationManager” or “NSLocale”?

余生颓废 提交于 2019-12-11 14:48:54

问题


I want to get my current country ; but I don't want to use "LocationManager" or "NSLocale" I just need the name of the country. any idea please?

Thanks a lot :)


回答1:


You should try to get Cellular information

#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

// Setup the Network Info and create a CTCarrier object
CTTelephonyNetworkInfo *networkInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [networkInfo subscriberCellularProvider];

// Get carrier name
NSString *carrierName = [carrier carrierName];
if (carrierName != nil)
  NSLog(@"Carrier: %@", carrierName);

// Get mobile country code
NSString *mcc = [carrier mobileCountryCode];
if (mcc != nil)
  NSLog(@"Mobile Country Code (MCC): %@", mcc);

// Get mobile network code
NSString *mnc = [carrier mobileNetworkCode];
if (mnc != nil)
  NSLog(@"Mobile Network Code (MNC): %@", mnc);

OR

You should try to get Country from the device IP Address

Identifying country by IP address




回答2:


I solved it by calling this url

http://www.geoplugin.net/json.gp

also you can call for testing http://www.geoplugin.net/json.gp?ip=3.255.255.255




回答3:


Try this please it will work 100 with latest PHP versions

$ip=$_SERVER['REMOTE_ADDR'];

$Details=unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));

If you want to check the complete array try this below one

echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip)));


来源:https://stackoverflow.com/questions/18589712/how-to-get-current-country-without-using-locationmanager-or-nslocale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!