返回顶部

收藏

程序内调用本地打电话功能-make a phone call

更多

利用openURL接口来调用打电话功能。代码还具备根据正则表达式判断电话好吗输入的合法性。

- (void)makeCall:(NSString *)number
{
 NSString *txt = number;
 NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{4}[-]{0,1}[0-9]{4}?" options:NSRegularExpressionSearch error:nil];
 NSTextCheckingResult *result = [regex firstMatchInString:txt options:0 range:NSMakeRange(0, [txt length])];
 NSString *cleanedString = [[[txt substringWithRange:[result range]] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
 NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", escapedPhoneNumber]];
 [[UIApplication sharedApplication] openURL:telURL];
}
//该片段来自于http://outofmemory.cn

标签:objective-c,手机开发

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-03-09 12:30:04UIViewController之间的切换 by 刘瑜
  2. 2014-05-06 15:35:36设置视图的圆角 by royacee
  3. 2014-05-26 20:31:21按照原比例来对视图进行缩放 by Sycro
  4. 2014-07-10 10:09:14判断是否是iPhone5 by 孙国强
  5. 2014-09-08 12:41:37打开设备闪关灯 by zetaliang
  6. 2014-09-21 12:39:43获取屏幕的高宽 by 王笃亭
  7. 2014-08-21 21:07:19iOS5和iOS6横竖屏同时支持 by panzaitang
  8. 2014-10-25 10:28:48禁止某几个文件用ARC模式编译 by lihuibng
  9. 2014-03-09 13:55:34IOS从背景图中取色 by 凤歌
  10. 2014-04-20 13:32:43视图翻转切换效果 by 牛哥
  11. 2014-06-15 10:54:58IOS画圆 by ccyuan

发表评论