2016-08-11 8 views
0

実際に私は電話でSimCardからプログラムコードを取得しようとしています。 Simcardからプログラムコードで国コードを取得するにはどうすればいいですか?または国コードの詳細を取得するのに役立つポッドがあります。事前どのようにsimCardからプログラムコードで国コードを取得するのですか?

+1

これらのリンクを試すhttp://stackoverflow.com/questions/9095023/ios-country-code とthis http://stackoverflow.com/questions/13584981/identifying-the-country-code-using-mobile-carrier -in-iphone-programatically –

答えて

2

1.ノート

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

CTCarrier *carrier = [[CTTelephonyNetworkInfo new] subscriberCellularProvider]; 
NSString *countryCode = carrier.isoCountryCode; 
NSLog(@"countryCode: %@", countryCode); 

Simcardのから、これは動作していない

1.Airplane mode. 
2.No SIM card in the device. 
3.Device is outside of cellular service range. 

2.からCurrentLocale

NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. 
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; 
NSLog(@"countryCode: %@", countryCode); 
場合3210
+0

飛行機モードでも動作しました – Husam

1

ありがとうございますが、インポートすることができます。

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

そして、このコードを使用:

CTCarrier* tmpCTC = [[CTCarrier alloc] init]; 
NSString* mcc = [tmpCTC mobileCountryCode]; 
NSLog([NSString stringWithFormat:@"mcc = %@",mcc]); 

は、それはあなたを助けることができると思います。

関連する問題