Making a phone call from apps

Here my app deals with phone call.After googling I found the code for calling a user from my app

NSURL *phoneNumber = [[NSURL alloc] initWithString: @"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];

This is my code.I don't know what is going on here, while making a call the device is using any protocols or else the code will initiate the normal dialing function of the device..

Whether itz compulsory to add Core Telephony Framework to my app?


Try this

Where pPhoneNumber is your string phone number..

    NSString *deviceName = [UIDevice currentDevice].model;    
    if([deviceName isEqualToString:@"iPhone"])
    {
        NSString *strDialedNumber = [pPhoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];      
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",strDialedNumber]]]; 
    }

尝试这个:-

NSString *telephoneString=[self.phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        NSMutableString *str1=[[NSMutableString alloc] initWithString:telephoneString];
        [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"(" withString:@""]];
        [str1 setString:[str1 stringByReplacingOccurrencesOfString:@")" withString:@""]];
        [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]];
        [str1 setString:[str1 stringByReplacingOccurrencesOfString:@" " withString:@""]];
        telephoneString = [@"tel://" stringByAppendingString:str1];
        [str1 release];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneString]];

If you run the code, iOS will make an outgoing call to the specified phone number. iOS uses its native Phone app to make the call.

Note that there should be no special characters in the phone number. It should contain only the numberic digits.

Have a look at the Reference from Apple.

链接地址: http://www.djcxy.com/p/62860.html

上一篇: 当应用程序在ios中处于后台时接收voip电话

下一篇: 从应用程序拨打电话