Make a call from my iPhone application

喜欢而已 提交于 2019-12-19 03:34:33

问题


I have implemented the ability to make a call from clicking on a row of descriptive tableview of my hotel; I used the URL scheme by writing the following code in method "didSelectRowAtIndexPath ":

NSString *phoneNumber=element.phone;                                       
[NSString *phoneNumberScheme = [NSString stringWithFormat:@"tel:%@ ", phoneNumber];
NSlog(phoneNumberScheme);                      
phoneNumberScheme = [phoneNumberScheme stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

No error! With NSlog I verified that the number was read correctly, and so it is (indeed on console appears tel:1-408-555-5555). The problem is that nothing happens!!!

At this point (also based on something I read on the web) I have a doubt that I can't test this thing on simulator! Am I doing something wrong or can't I test this "URL scheme" on the simulator?!


回答1:


To expand on seanny94's answer: 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.




回答2:


You can't test a phone call (or any phone-based function, for that matter) in the Simulator. There is no support for it.




回答3:


Try this useful code

Remove spaces for your code

NSString *trimmedString = [yourNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];

Code for Call after confirmation

NSString *phoneNumber = [@"telprompt://" stringByAppendingString:trimmedString];

Code for direct calling

NSString *phoneNumber = [@"tel://" stringByAppendingString:trimmedString];
NSLog(@"Number : %@",phoneNumber);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];


来源:https://stackoverflow.com/questions/3282778/make-a-call-from-my-iphone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!