How to tell if Cocoa Touch device can make calls?

Will Harris picture Will Harris · May 24, 2009 · Viewed 9.1k times · Source

Possible Duplicate:
iOS - Detecting whether or not device support phone calls?

I'm writing an iPhone application that provides a button to call a phone number. I'm using code like the following to dial the number using a tel: URL in the usual way:

NSURL* contactTelURL = [NSURL
                        URLWithString:[NSString
                                       stringWithFormat:@"tel:%@",
                                       contactTel]];
[[UIApplication sharedApplication] openURL:contactTelURL];

It works fine on a real iPhone, but I just get an 'Unsupported URL' alert in the simulator. Presumably that would also happen on an iPod Touch, though I haven't tested that. It would be nice to remove the button when running on a device that won't make calls.

Is there a way to detect programatically whether a Cocoa Touch device can make phone calls?

Answer

neilkimmett picture neilkimmett · Aug 27, 2010

From Noah Witherspoon at Make a call from my iPhone application

the simulator doesn't support a lot of iOS's URL schemes, including those for the Phone, Maps, Youtube, and SMS apps. This is also the case for devices like the iPod touch and the iPad, which don't have phone capabilities; before using any URL scheme via -openURL:, you should check for support for that scheme using -canOpenURL:, which will return YES or NO depending on whether the current device supports the URL scheme you're using

So query [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]] to find out if the device can make calls.