如何在 iOS 中获取用户的国家/地区呼叫代码?

How to get the user#39;s country calling code in iOS?(如何在 iOS 中获取用户的国家/地区呼叫代码?)
本文介绍了如何在 iOS 中获取用户的国家/地区呼叫代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发一个 iOS 应用,用户可以在其中输入他们的手机号码.我如何获得他们的国家电话代码?例如,如果用户在印度,则应自动添加 +91 前缀.有没有自动添加国家代码的选项?

解决方案

导入声明:

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

您可以使用 CoreTelephony 框架获取当前运营商的国家/地区代码:

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];CTCarrier *carrier = network_Info.subscriberCellularProvider;NSLog(@"国家代码为:%@",carrier.mobileCountryCode);//将返回实际的国家代码NSLog(@"ISO 国家代码为:%@", carrier.isoCountryCode);

Apple 文档p>

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 should be prefixed automatically. Is there an option that adds country codes automatically?

解决方案

Import Statement :

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

you can get country code for the current Carrier using CoreTelephony framework:

CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;

NSLog(@"country code is: %@", carrier.mobileCountryCode);

//will return the actual country code
NSLog(@"ISO country code is: %@", carrier.isoCountryCode);

Apple Docs

这篇关于如何在 iOS 中获取用户的国家/地区呼叫代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)