How to make call from iphone app on xml parser value?

亡梦爱人 提交于 2019-12-25 07:51:23

问题


I am still not able to make phone call using previous answer. I am parsing xml file to get phone number values (aMarker.phone= phone number). Where marker is attributes in xml file which I am fetching in my parser controller. I am able to set this phone number string on Button title. But by tapping button I am not able to call the number. See my code

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath {
 if(BGView.hidden == YES)
{
BGView.hidden = NO;

NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
  marker *aMarker = (marker *)[appDelegate.markers objectAtIndex:selectedIndexPath.row];
for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count];    selectedIndexPath++)
{       [p_Bcard setTitle:[NSString stringWithFormat:@"%@",aMarker.phone]forState:UIControlStateNormal];
 //getting correct number on p_Bcard button title.
}
}}

Button Action code:

 -(IBAction)phonecallUpadated
  {
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];

marker *aMarker = (marker *)[appDelegate.markers  objectAtIndex:selectedIndexPath.row];
for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count];  selectedIndexPath++)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",aMarker.phone]]];

 //not able to call pressing p_Bcard button using above action. method get call by setting breakpoint. 

What should I do here to pass proper string number to make phone call. }


回答1:


First of all convert your phone number to UTF8 encoding string then make NSURL. another wise set %20 between two words (between two phone no).




回答2:


To make phone call, you need to have append tel: with the phone number. It should be as follows:

NSString *phone_number = @"18005551212"; // get dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone_number]]];


来源:https://stackoverflow.com/questions/8165796/how-to-make-call-from-iphone-app-on-xml-parser-value

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