Posted By

peruggia on 11/02/11


Tagged

call iphone iPad ios


Versions (?)

Make a call (iPhone)


 / Published in: Objective C
 

  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. }

Report this snippet  

You need to login to post a comment.