通过应用程序拨打电话

时间:2011-08-25 05:38:57

标签: iphone objective-c ios

在这里,我的应用程序处理电话。谷歌搜索后,我找到了从我的应用程序调用用户的代码

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

这是我的代码。我不知道这里发生了什么,在拨打电话时设备正在使用任何协议,否则代码将启动设备的正常拨号功能..

是否必须将Core Telephony Framework添加到我的应用程序中?

4 个答案:

答案 0 :(得分:3)

试试这个

pPhoneNumber是你的字符串电话号码..

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

答案 1 :(得分:2)

如果您运行代码,iOS会将 拨打电话 拨打到指定的电话号码。 iOS使用其原生电话应用程序拨打电话。

请注意,电话号码中不应包含特殊字符。它应该只包含数字。

查看Reference from Apple

答案 2 :(得分:2)

试试这个: -

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]];

答案 3 :(得分:0)

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