编程实现iPhone发送短信SMS

fmms 13年前
     <p>在iPhone应用中开发中,可以使用MFMessageComposeViewController标准短信SMS发送界面来完成。在使用之前,需要实现MFMessageComposeViewControllerDelegate代理,这个代理提供了短信发送相关的接口。</p>    <pre class="brush:cpp; toolbar: true; auto-links: false;">#import                     <uikit uikit.h="">                           #import                          <messageui mfmessagecomposeviewcontroller.h="">                                <span class="referer">@interface</span> TestViewController : UIViewController                               <mfmessagecomposeviewcontrollerdelegate>                                    {   UIButton *buttonSMS; }   @end                              </mfmessagecomposeviewcontrollerdelegate>                         </messageui>                    </uikit></pre>    <p></p>    <p>在TestViewController实现体中编写发送短信的方法sendSMS,如下:</p>    <pre class="brush:cpp; toolbar: true; auto-links: false;">- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients {   MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];   if([MFMessageComposeViewController canSendText])   {     controller.body = bodyOfMessage;         controller.recipients = recipients;     controller.messageComposeDelegate = self;     [self presentModalViewController:controller animated:YES];   }     }   // 处理发送完的响应结果 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {   [self dismissModalViewControllerAnimated:YES];     if (result == MessageComposeResultCancelled)     NSLog(@"Message cancelled")   else if (result == MessageComposeResultSent)     NSLog(@"Message sent")     else      NSLog(@"Message failed")   }</pre>    <p></p>    <p>sendSMS:方法中打开MFMessageComposeViewController发送短信界面:</p>    <p><img title="" alt="编程实现iPhone发送短信SMS" src="https://simg.open-open.com/show/2a72c393e860c66828ea17c08edd1796.png" width="250" height="375" /></p>    <p>文章出处:<a href="/misc/goto?guid=4959500502529922637" rel="nofollow">http://www.ctolive.com/space-1023-do-blog-id-2095.html</a></p>