Iphone的发送短信-邮件-打电话代码示例(转)

时间:2022-11-10 14:24:46

Iphone的发送短信-邮件-打电话代码示例

2011-02-23 09:43:48 作者: jezz  资深编辑 有1024人浏览  网友评论 0 条
Iphone的发送短信-邮件-打电话代码示例 : 
01. + (void)alert:(NSString *)msg
02. {
03. UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:msg message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
04. [alertView showWithBackground];
05. }
06.  
07. + (NSString*) cleanPhoneNumber:(NSString*)phoneNumber
08. {
09. NSString* number = [NSString stringWithString:phoneNumber];
10. NSString* number1 = [[[number stringByReplacingOccurrencesOfString:@" " withString:@""]
11. //                        stringByReplacingOccurrencesOfString:@"-" withString:@""]
12. stringByReplacingOccurrencesOfString:@"(" withString:@""]
13. stringByReplacingOccurrencesOfString:@")" withString:@""];
14.  
15. return number1;   
16. }
17.  
18. + (void) makeCall:(NSString *)phoneNumber
19. {
20. if ([DeviceDetection isIPodTouch]){
21. [UIUtils alert:kCallNotSupportOnIPod];
22. return;
23. }
24.  
25. NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];   
26.  
27. NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", numberAfterClear]];
28. NSLog(@"make call, URL=%@", phoneNumberURL);
29.  
30. [[UIApplication sharedApplication] openURL:phoneNumberURL];   
31. }
32.  
33. + (void) sendSms:(NSString *)phoneNumber
34. {
35. if ([DeviceDetection isIPodTouch]){
36. [UIUtils alert:kSmsNotSupportOnIPod];
37. return;
38. }
39.  
40. NSString* numberAfterClear = [UIUtils cleanPhoneNumber:phoneNumber];
41.  
42. NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"sms:%@", numberAfterClear]];
43. NSLog(@"send sms, URL=%@", phoneNumberURL);
44. [[UIApplication sharedApplication] openURL:phoneNumberURL];   
45. }
46.  
47. + (void) sendEmail:(NSString *)phoneNumber
48. {
49. NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", phoneNumber]];
50. NSLog(@"send sms, URL=%@", phoneNumberURL);
51. [[UIApplication sharedApplication] openURL:phoneNumberURL];   
52. }
53.  
54. + (void) sendEmail:(NSString *)to cc:(NSString*)cc subject:(NSString*)subject body:(NSString*)body
55. {
56. NSString* str = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@",
57. to, cc, subject, body];
58.  
59. str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
60.  
61. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
62.  
63. }