问题
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