以编程方式在iPhone上拨打紧急电话 [英] Programmatically making an emergency call on iPhone

查看:133
本文介绍了以编程方式在iPhone上拨打紧急电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个按钮,用户可以通过该按钮拨打紧急服务。

I'd like to make a button with which the user can dial through to emergency services.

似乎没有任何具体方法可以拨打这样做,所以我想我必须使用

There doesn't seem to be any specific method to call to do this, so I think I have to use

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

并自行分配phoneNumber。然而,虽然我知道这是美国的911,英格兰的999等,但我不确定如何确定用户所在的国家/地区 - 我可以检索他们的语言环境,但是如果他们手动设置他们的语言环境或者在国外旅行,它不可靠。我可以解决他们的位置问题,但如果他们关闭GPS或没有互联网连接,它将无法工作。

and assign the phoneNumber myself. However, while I know this is 911 in the US, 999 in England, etc I'm not sure how to determine what country the user is in - I can retrieve their locale, but if they set their locale manually or travel outside their country, it wouldn't be reliable. I can resolve their location, but it won't work if they've turned off GPS or don't have internet connectivity.

我听说112现在是GSM手机上的通用标准 - 它适用于所有iPhone吗?

I've heard 112 is now a universal standard on GSM phones - will it work on all iPhones?

推荐答案

我不确定如何获取不同的数字,但假设您有一组这些(让我们说一个国家/地区的字典),那么您可以使用网络信息来决定手机当前所在的国家/地区。

I'm not sure on how to obtain the different numbers, but assuming you have a set of these (let's say a dictionary by country), then you can use the network information on deciding which country the phone is currently located in.

您可以使用CoreTelephony框架,特别是 CTTelephonyNetworkInfo CTCarrier 类来实现。这是一个小样本,它将获得当前运营商的ISO 3166-1国家/地区代码。

You can do that by using the CoreTelephony framework, specifically the CTTelephonyNetworkInfo and CTCarrier classes. Here's a small sample that will obtain the ISO 3166-1 country code of the current carrier.

CTTelephonyNetworkInfo *network = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [network subscriberCellularProvider];
NSString *countryCode = [carrier isoCountryCode];

现在 countryCode 将拥有代码(至我所知道的Alpha-2代码,对每个国家来说都是独一无二的,这里列出了这些

Now countryCode will have the code (to my knowledge the Alpha-2 code), that is unique for each country, here's a list of these

这篇关于以编程方式在iPhone上拨打紧急电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆