iOS开发常用

时间:2023-12-27 08:39:07

http://blog.csdn.net/u013043666/article/details/51353386

1.打电话

第一种

 NSString *telNum = model.contact;

        NSArray *replaces = @[@"-",@"+",@" "];

        for (NSString *item in replaces) {
telNum = [telNum stringByReplacingOccurrencesOfString:item withString:@""];
} NSString *phoneNumber = [NSString stringWithFormat:@"telprompt://%@",telNum];
NSURL *url = [NSURL URLWithString:phoneNumber]; if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}

第二种

        UIWebView *callWebView = [[UIWebView alloc]init];
NSString *phoneNumber = [NSString stringWithFormat:@"tel://%@",model.contact];
NSURL *url = [NSURL URLWithString:phoneNumber];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[callWebView loadRequest:request];
[self.view addSubview:callWebView];