IOS 程序内调用本地打电话功能-make a phone call
生活随笔
收集整理的這篇文章主要介紹了
IOS 程序内调用本地打电话功能-make a phone call
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
利用openURL接口來調用打電話功能。代碼還具備根據正則表達式判斷電話好嗎輸入的合法性。
1 - (void)makeCall:(NSString *)number 2 { 3 NSString *txt = number; 4 NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{4}[-]{0,1}[0-9]{4}?" options:NSRegularExpressionSearch error:nil]; 5 NSTextCheckingResult *result = [regex firstMatchInString:txt options:0 range:NSMakeRange(0, [txt length])]; 6 NSString *cleanedString = [[[txt substringWithRange:[result range]] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""]; 7 NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 8 NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", escapedPhoneNumber]]; 9 [[UIApplication sharedApplication] openURL:telURL]; 10 }?
轉載于:https://www.cnblogs.com/ubersexual/archive/2013/03/29/2988789.html
總結
以上是生活随笔為你收集整理的IOS 程序内调用本地打电话功能-make a phone call的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 学习 swing 应该学习到什
- 下一篇: 2013ACM多校联合(2)