Abhinav
Abhinav

Reputation: 38162

Error while calling a phone number from iPhone app

I am using following code to make a phone call from my iPhone app:

NSURL *myPhone1 = [NSURL URLWithString:@"14165551212"];
[myPhone1 scheme:@"tel://"];
NSURLRequest *myPhoneReq = [[NSURLRequest alloc ] requestWithURL:myPhone1];
NSURLConnection *myCon = [[NSURLConnection alloc] initWithRequest:myPhoneReq delegate:self];

but getting following error: 'NSInvalidArgumentException', reason: '-[NSURL scheme:]: unrecognized selector sent to instance 0x6a10ba0

Any idea how to achieve this?

Upvotes: 2

Views: 292

Answers (2)

Aaron Saunders
Aaron Saunders

Reputation: 33345

[[UIApplication sharedApplication] 
                    openURL:[NSURL URLWithString:@"tel: 14165551212"]];

will not work in simulator

Upvotes: 2

esqew
esqew

Reputation: 44695

All you need to do is this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://14165551212"]]

That might fix your problem, however it won't work in the iPhone simulator.

Upvotes: 0

Related Questions