首先:
Frameworks中要引入MessageUI.framework
#import <MessageUI/MessageUI.h>
添加协议:<MFMessageComposeViewControllerDelegate>
之后看代码:
有两种短信调用,1种是调用系统内的短信功能,可以发完短信返回app,另一种调用系统外的发短信功能,不能反悔app
//调用系统内的发短信功能,可以返回app
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *picker =
[[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.navigationBar.tintColor = [UIColor blackColor];
// 默认收件人(可多个)
picker.recipients = [NSArray arrayWithObject:@"",@""];
picker.body = @"aaaaaaaaaa";
[self presentViewController:picker
animated:YES
completion:^{
}];
}else{
//调用系统外的发短信功能,不能返回app
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",mobile]]];
}
}
#pragma mark - MFMessageComposeViewControllerDelegate
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
showMsg(@"发送取消");
break;
case MessageComposeResultSent:
showMsg(@"发送成功");
break;
case MessageComposeResultFailed:
showMsg(@"发送失败");
break;
default:
break;
}
[controller dismissViewControllerAnimated:NO completion:^{
}];
}
大电弧功能
NSString* deviceType = [UIDevice currentDevice].model;
return [deviceType isEqualToString:@"iPhone"];
if (![Method isPhoneSupported]) {
showMsg(@"当前设备不支持拨打电话");
return NO;
}
NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", num]];
[[UIApplication sharedApplication] openURL:telURL];
版权声明:本文为博主原创文章,未经博主允许不得转载。