>

不能初始化SMS内容,但是这样写之后有个缺点就

- 编辑:澳门博发娱乐官网 -

不能初始化SMS内容,但是这样写之后有个缺点就

controller.recipients = [NSArray arrayWithObject:phoneNumber];//接收人,可以有很多,放入数组

-(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;

}

1.点击按钮复制

UIPasteboard *pab = [UIPasteboard generalPasteboard];

NSString *string = @"测试";

[pab setString:string];

if (pab == nil) {

[SVProgressHUD showErrorWithStatus:@"复制失败"];

[SVProgressHUD dismissWithDelay:.3];

}else

{

[SVProgressHUD showSuccessWithStatus:@"已复制"];

[SVProgressHUD dismissWithDelay:.3];

}

 

controller.recipients = [NSArray arrayWithObject:@"10010"];

NSString *usrString = [NSString stringWithFormat:@"sms://%@", @"132424123124"];

}

2.调用系统发送短信

实现此功能,一般使用程序内调用系统。首先将头文件引入

#import<MessageUI/MessageUI.h>

实现代码

if( [MFMessageComposeViewController canSendText]) {

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

controller.recipients = @[@"10086"];//发送短信的号码,数组形式入参

controller.navigationBar.tintColor = [UIColor redColor];

controller.body = @"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];

}

如要获取发送状态,遵守代理MFMessageComposeViewControllerDelegate并实现代理方法

-(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;

}

}

如果想要发送短信之后留在短信页面直接用openUrl

实现代码

NSString *phoneStr = [NSString stringWithFormat:@"10086"];//发短信的号码

NSString *smsContentStr = [NSString stringWithFormat:@"短信内容"];

NSString *urlStr = [NSString stringWithFormat:@"sms://%@&body=%@ ", phoneStr, smsContentStr];

NSURL *url = [NSURL URLWithString:urlStr];

[[UIApplication sharedApplication] openURL:url];

 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10010"]];

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

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

 

}

{

else{

// 处理发送完的响应结果

添加协议:

于是乎就有了下面的写法:

[selfshowTips:@"您的手机无法送短信"];

-(void)sendMail:(NSString *)subject content:(NSString *)content{

上面的代码只是把第一个方法中的tel为telprompt.

controller.body = @"ssssssss";//短信内容,自定义即可

}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title

{

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

 

print?

[[[[controller viewControllers] lastObject] navigationItem] setTitle:@"发送短信"];//修改短信界面标题

if( [MFMessageComposeViewController canSendText] )

//内容,收件人列表

}

NSLog(@"不能发送短信");

2)实现代理方法MFMessageComposeViewControllerDelegate

 

controller.body = @"测试发短信";

一般情况下,我们可以这样调用短信功能这样写

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

1、调用 自带mail

使用openURL这个API打电话结束后,返回的是系统的拨打电话界面,如何才能返回自己的应用呢?有两种方法与大家分享。

-showMessageViewController:(NSString*)phoneNumber

controller.messageComposeDelegate =self;

 

if( [MFMessageComposeViewController canSendText] ){

else

这对app来说非常重要。

 

- (void) alertWithTitle:(NSString *)title msg:(NSString *)msg {

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

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

 

1、打电话

}

#import <MessageUI/MessageUI.h>

在.xib 中的Localization添加一組chinese就ok了

[cpp]view plaincopy

if( [MFMessageComposeViewController canSendText] )//判断是否能发短息

}

 

caseMessageComposeResultCancelled:

}

controller.recipients = list;

 

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

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:usrString]];

程序内调用系统发短信

}

}

controller.messageComposeDelegate = self;//注意不是delegate

controller.messageComposeDelegate = self;

 

print?

{

[selfpresentViewController:controller animated:YEScompletion:nil];

 

代码如下:

本文由胜博发-编程发布,转载请注明来源:不能初始化SMS内容,但是这样写之后有个缺点就