Toby
Toby

Reputation: 390

Programmatically making an emergency call on 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]];

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.

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

Upvotes: 5

Views: 3363

Answers (2)

Henri Normak
Henri Normak

Reputation: 4725

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.

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];

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

Upvotes: 9

DrummerB
DrummerB

Reputation: 40221

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]];

This is correct.

Regarding what number to dial, I don't think there is a global emergency number.

Upvotes: 0

Related Questions