打电话
- (void)phoneCall:(NSString *)phoneNumber {
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", cleanedString]];
UIApplication *myApp = [UIApplication sharedApplication];
[myApp openURL:telURL];
}
发短信
+(void)sms:(NSString *)phoneNumber
{
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"sms:%@", cleanedString]];
UIApplication *myApp = [UIApplication sharedApplication];
[myApp openURL:telURL];
}