简体   繁体   中英

How can I initiate a phone call programmatically on the iPhone in iOS 5?

How can I initiate a phone call programmatically on the iPhone in iOS 5? i tried the following code call functionality is working fine but when I click the cancel button, It is displaying black screen.

    NSString *phoneUrl;
phoneUrl=@"9866510857";

NSString *phoneNumber = [@"tel://" stringByAppendingString:phoneUrl];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

1) Drop the // so you just have "tel:9866510857". I'm not sure if they hurt, but they definitely aren't necessary (see https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html ).

2) Make sure you aren't testing on the simulator; it doesn't have a phone app, so nothing will happen regardless. Test on an actual iPhone if you haven't been doing so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM