首先:
Frameworks中要引入MessageUI.framework
#import添加协议:<MFMessageComposeViewCont
之后看代码:
有两种短信调用,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];
本文详细介绍了如何在iOS应用中实现短信和电话功能,包括系统内短信发送、系统外短信发送、拨打电话功能的调用及异常处理。
8299

被折叠的 条评论
为什么被折叠?



