本文主要是介绍iphone 编程实现发短信功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在iPhone应用中开发中,可以使用MFMessageComposeViewController标准短信SMS发送界面来完成。在使用之前,需要实现MFMessageComposeViewControllerDelegate代理,这个代理提供了短信发送相关的接口。
1 2 3 4 5 6 7 8 9 | #import <UIKit/UIKit.h> #import <MessageUI/MFMessageComposeViewController.h> <a class = "referer" href= "http://my.oschina.net/interface" target= "_blank" >@interface</a> TestViewController : UIViewController <MFMessageComposeViewControllerDelegate> { UIButton *buttonSMS; } @end |
在TestViewController实现体中编写发送短信的方法sendSMS,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | - ( 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" ) } |
文章出处:http://www.ctolive.com/space-1023-do-blog-id-2095.html
这篇关于iphone 编程实现发短信功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!