少尉

嗯。

 

iphone-调系统电话,短信等功能(自动返回程序)

        iphone-调系统电话,短信等功能(自动返回程序)       

分类:            Iphone 应用开发35人阅读评论(0)收藏举报

方法一:

  1. //在iPhone中,可以直接用UIApp打开URL地址。如下所示: 
  2. [ UIApp openURL: [ NSURL URLWithString:@"http://www.apple.com" ] ]; 
  3.  
  4. //或者: 
  5. [ UIApp openURL: [ NSURL URLWithString:@"mailto:apple@mac.com?Subject=hello" ] ]; 
  6.  
  7. //与此同时,iPhone还包含一些其他除了http://或者mailto:之外的URL: 
  8.  
  9. sms:// 可以调用短信程序 
  10.  
  11. tel:// 可以拨打电话 
  12.  
  13. itms:// 可以打开MobileStore.app 
  14.  
  15. audio-player-event:// 可以打开iPod 
  16.  
  17. audio-player-event://?uicmd=show-purchased-playlist 可以打开iPod播放列表 
  18.  
  19. video-player-event:// 可以打开iPod中的视频 

以简单使用系统功能,但使用系统功能后无法自动回到程序原界面,

 

电话,短信,邮件功能可用以下方法

方法二:

电话

  1. NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", PhoneNumber]; 
  2. NSLog(@"call phone %@;", mobileNumber); 
  3. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]]; 

邮件 使用MFMailComposeViewController

 

引入头文件 #import <MessageUI/MFMailComposeViewController.h>

  1. //发邮箱     
  2. Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
  3.     if (mailClass != nil) 
  4.     { 
  5.         // We must always check whether the current device is configured for sending emails 
  6.         if ([mailClass canSendMail]) 
  7.         { 
  8.             [self displayMailComposerSheet:MailNumber]; 
  9.         } 
  10.         else 
  11.         { 
  12.             [self launchMailAppOnDevice]; 
  13.         } 
  14.     } 
  15.     else 
  16.     { 
  17.         [self launchMailAppOnDevice]; 
  18.     } 
  1. //---------------------------------- 
  2.  
  3. -(void)displayMailComposerSheet:(NSString *)strMail 
  4.     NSLog(@"displayMailComposerSheet"); 
  5.     if (_Emailpicker == nil) { 
  6.         _Emailpicker = [[MFMailComposeViewController alloc] init]; 
  7.         _Emailpicker.mailComposeDelegate = self; 
  8.          
  9.         [_Emailpicker setSubject:@""]; 
  10.     } 
  11.     // Set up recipients 
  12.      
  13.     NSArray *toRecipients = [NSArray arrayWithObject:strMail];   
  14.     [_Emailpicker setToRecipients:toRecipients]; 
  15.     [_Emailpicker setMessageBody:@"" isHTML:NO]; 
  16.      
  17.     <pre class="cpp" name="code">[self presentModalViewController:Emailpicker animated:YES]; 
  18.      
  19.  
  20.  
  21. -(void)launchMailAppOnDevice 
  22.     MyLog(@"launchMailAppOnDevice"); 
  23.  
  24. // Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation. 
  25. </pre>//发送完邮件<br> 
  26. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {[controller dismissModalViewControllerAnimated:NO];//邮件视图下拉消失}<p></p> 
  27. <pre></pre> 
  28. <br> 
  29. 短信:(使用MFMessageComposeViewController ) 
  30. <p></p> 
  31. <p><pre class="cpp" name="code">Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); 
  32.     NSLog(@"can send SMS [%d]", [messageClass canSendText]); 
  33.      
  34.     if (messageClass != nil) { 
  35.         if ([messageClass canSendText]) { 
  36.             [self displayMessageComposerSheet:MsmNumber]; 
  37.         } else
  38.             [self launchMessageAppOnDevice];//<span style="color: rgb(227, 0, 9);">设备没有短信功能</span> 
  39.         } 
  40.     } else
  41.         [self launchMessageAppOnDevice];//iOS版本过低,iOS4.0以上才支持程序内发送短信 
  42.     } 
  43. </pre><p></p> 
  44. <p><pre class="cpp" name="code">-(void)displayMessageComposerSheet:(NSString *)strMail 
  45.     MyLog(@"displayMessageComposerSheet"); 
  46.     MFMessageComposeViewController *messagePicker = [[MFMessageComposeViewController alloc] init]; 
  47.     messagePicker.messageComposeDelegate = self; 
  48.     messagePicker.body = @""
  49.     [self presentModalViewController:messagePicker animated:YES]; 
  50.      
  51. //  [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:_Emailpicker animated:YES]; 
  52.     [messagePicker release]; 
  53.  
  54. -(void)launchMessageAppOnDevice 
  55.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此设备不支持发送短信或系统版本过低" delegate:nil cancelButtonTitle:@"确定 " otherButtonTitles:nil, nil]; 
  56.     [alert show]; 
  57.     [alert release]; 
  58.  
  59. - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 
  60.     [controller dismissModalViewControllerAnimated:NO]; 
  61. </pre><br> 
  62. <br> 
  63. <br> 
  64. <p></p> 
  65. <br> 

posted on 2012-08-16 11:49  moonvan  阅读(1015)  评论(0编辑  收藏  举报

导航