开发者

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 o开发者_如何转开发r 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]]]; 
    }


try this:-

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.


[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9016098909891"]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜