网站建设资讯

NEWS

网站建设资讯

ios开发发送短信,ios开发 读取短信

IOS怎样使用MessageUI Framework 发送短信息

IOS怎样使用MessageUI Framework 发送短信息。使用MessageUI Framework 中的 MFMessageComposeViewController 发送短信息,另外其中的MFMailComposeViewController用于发送邮件。使用非常简单:

目前创新互联公司已为上1000家的企业提供了网站建设、域名、网页空间、网站运营、企业网站设计、曲水网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

导入框架:MessageUI.framework

2. 添加协议:MFMessageComposeViewControllerDelegate

3. #import MessageUI/MessageUI.h

1 //判断当前设备是否可以发送短信息

2 if([MFMessageComposeViewController canSendText])

3 {

4

5 MFMessageComposeViewController *mc = [[MFMessageComposeViewController alloc] init];

6 //设置委托

7 mc.messageComposeDelegate = self;

8 //短信内容

9 mc.body = @"nihao";

10 //短信接收者,可设置多个

11 mc.recipients = [NSArray arrayWithObject:@"10086",nil];

12

13 [self presentModalViewController:mc animated:YES];

14 [mc release];

15 }

16 else

17 {

18 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error",

19 message:@"The current device can not send SMS"

20 delegate:nil

21 cancelButtonTitle:"OK",

22 otherButtonTitles:nil];

23 [alert show];

24 [alert release];

25 }

26

27

28 #pragma mark -

29 #pragma mark MFMessageComposeViewControllerDelegate

30 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

31 {

32 switch(result)

33 {

34 case MessageComposeResultCancelled:

35 ...

36 case MessageComposeResultFailed:

37 ...

38 case MessageComposeResultSend:

39 ...

40 default:

41 ...

42 }

43 }

【iOS】短信发送

这个方法,并不是很高级,因为只能写好联系人,下面提供一个方法,可以直接编辑好内容还有收信人的!

不过本人求一个方法,可以直接把短信给发送出去了的,为这个方法只能编辑好,最后还是要用户自己点击一下发送按钮,有不有什么方法可以直接发送出去了呢!希望各位赐教留言!!

iOS 短信调用

pre[[UIApplication sharedApplication]openURL:[NSURL URLWithString:

@sms://13888888888]];

-(void)messageComposeViewController(MFMessageComposeViewController*)controller didFinishWithResult:(MessageComposeResult)result

{

[self dismissViewControllerAnimated:YES completion:nil];

switch

(result) {

case

MessageComposeResultSent:

信息传送成功

break;

case

MessageComposeResultFailed:

信息传送失败

break;

case

MessageComposeResultCancelled:

信息被用户取消传送

break;

default:

break;

}

}/pre

程序内调用系统发短信

pre

实现代理方法MFMessageComposeViewControllerDelegate

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

{

[self dismissViewControllerAnimated:YES completion:nil];

switch (result) {

case MessageComposeResultSent:

//信息传送成功

}

/pre

发送短信

pre

-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body

{

if( [MFMessageComposeViewController canSendText] )

{

MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];

controller.recipients = phones;

controller.navigationBar.tintColor = [UIColor redColor];

controller.body = body;

controller.messageComposeDelegate = self;

[self presentViewController:controller animated:YES completion:nil];

[[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题

}

else

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@提示信息

message:@该设备不支持短信功能

delegate:nil

cancelButtonTitle:@确定

otherButtonTitles:nil, nil];

[alert show];

}

}

参数phones:发短信的手机号码的数组,数组中是一个即单发,多个即群发。

/pre

调用发短信的方法

pre

[self showMessageView:[NSArray arrayWithObjects:@13888888888,@13999999999, nil] title:@test body:@你是土豪么,么么哒];

/pre


网页题目:ios开发发送短信,ios开发 读取短信
URL地址:http://cdweb.net/article/dsieccd.html