如何在不使用“LocationManager”的情况下获取当前国家/地区或“NSLocale”? [英] How to get current country without using "LocationManager" or "NSLocale"?
本文介绍了如何在不使用“LocationManager”的情况下获取当前国家/地区或“NSLocale”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想得到我现在的国家;但我不想使用LocationManager或NSLocale
我只需要该国家的名称。
有什么想法吗?
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?
非常感谢:)
推荐答案
你应该尝试获取蜂窝信息
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
您应该尝试从设备IP地址获取国家/地区
You should try to get Country from the device IP Address
这篇关于如何在不使用“LocationManager”的情况下获取当前国家/地区或“NSLocale”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文