Make a call (iPhone)


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.