编程实现iPhone发送短信SMS
<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>
本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!