发送短信/邮件/打电话的代码

这是CocoaChina会员 qqn_pp 分享的代码,帖子地址 http://www.cocoachina.com/bbs/read.php?tid-20993.html + (void)alert:(NSString *)msg { UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:msg message:@ delegate:self cance

这是CocoaChina会员 “qqn_pp” 分享的代码,帖子地址 http://www.cocoachina.com/bbs/read.php?tid-20993.html

+ (void)alert:(NSString *)msg

{

UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:msg message:@”” delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil] autorelease];

[alertView showWithBackground];

}

+ (NSString*) cleanPhoneNumber:(NSString*)phoneNumber

{

NSString* number = [NSString stringWithString:phoneNumber];

NSString* number1 = [[[number stringByReplacingOccurrencesOfString:@” ” withString:@””]

// stringByReplacingOccurrencesOfString:@”-” withString:@””]

stringByReplacingOccurrencesOfString:@”(” withString:@””]

stringByReplacingOccurrencesOfString:@”)” withString:@””];

return number1;

}

+ (void) makeCall:(NSString *)phoneNumber

{

if ([DeviceDetection isIPodTouch]){

[UIUtils alert:kCallNotSupportOnIPod];

return;

}

NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];

NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@”tel:%@”, numberAfterClear]];

NSLog(@”make call, URL=%@”, phoneNumberURL);

[[UIApplication sharedApplication] openURL:phoneNumberURL];

}

+ (void) sendSms:(NSString *)phoneNumber

{

if ([DeviceDetection isIPodTouch]){

[UIUtils alert:kSmsNotSupportOnIPod];

return;

}

NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];

NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@”sms:%@”, numberAfterClear]];

NSLog(@”send sms, URL=%@”, phoneNumberURL);

[[UIApplication sharedApplication] openURL:phoneNumberURL];

}

+ (void) sendEmail:(NSString *)phoneNumber

{

NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@”mailto:%@”, phoneNumber]];

NSLog(@”send sms, URL=%@”, phoneNumberURL);

[[UIApplication sharedApplication] openURL:phoneNumberURL];

}

+ (void) sendEmail:(NSString *)to cc:(NSString*)cc subject:(NSString*)subject body:(NSString*)body

{

NSString* str = [NSString stringWithFormat:@”mailto:%@?cc=%@&subject=%@&body=%@”,

to, cc, subject, body];

str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

}

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注