@interface EVCommunicateHandler()<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
@property(nonatomic,strong)MFMessageComposeViewController * mobileContactsVC;
@property(nonatomic,strong) UIViewController * parentcontroller;
@end
@implementation EVCommunicateHandler
#pragma mark - 打电话
-(void)tel:(NSString*)telPhoneNumber{
// 提示拨打方法1:
// NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telPhoneNumber];
// UIWebView * callWebview = [[UIWebView alloc] init];
// [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
// [self.view addSubview:callWebview];
// 提示拨打方法2:
//tel or telprompt
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@", telPhoneNumber]];
// 调用openURL:
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
#pragma 发短信
+(void)message:(NSString *)phoneNum content:(NSString *)content{
NSURL *url = [NSURL URLWithString:@"sms://10010"];[[UIApplication sharedApplication] openURL:url];
}
/**
* 指定内容 打开SMS
*
* @param bodyOfMessage 要发送的内容
* @param recipients 要发送的号码
*/
- (void)sendSMS:(UIViewController *)parentcontroller contend:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
_parentcontroller = parentcontroller;
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[parentcontroller presentViewController:controller animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled)
{
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent)
{
NSLog(@"Message sent");
}
else
{
NSLog(@"Message failed");
}
}
#pragma mark - 发邮件
/**
发送邮件
@param parentcontroller 控制器
@param theme 主题
@param bodyOfMessage 内容
@param recipients 收件邮件
@param ccRecipients 抄送邮箱
@param auth 权限
*/
-(void)sendEmail:(UIViewController *)parentcontroller theme:(NSString *)theme contend:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients ccRecipients:(NSArray *)ccRecipients auth:(void(^)(BOOL auth,NSString * errorStr))auth{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (!mailClass) {
//[self alertWithMessage:@"当前系统版本不支持应用内发送邮件功能,您可以使用mailto方法代替"];
!auth?:auth(NO,@"当前系统版本不支持应用内发送邮件功能");
return;
}
if (![mailClass canSendMail]) {
//[self alertWithMessage:@"用户没有设置邮件账户"];
!auth?:auth(NO,@"用户没有设置邮件账户");
return;
}
MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
//设置邮件主题
[vc setSubject:theme];
//设置邮件内容
[vc setMessageBody:bodyOfMessage isHTML:NO];
//设置收件人列表
[vc setToRecipients:recipients];
//设置抄送人列表
[vc setCcRecipients:ccRecipients];
//设置代理
vc.mailComposeDelegate = self;
//显示控制器
[parentcontroller presentViewController:vc animated:YES completion:nil];
}
// 实现代理方法:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[controller dismissViewControllerAnimated:YES completion:nil];
//[_parentcontroller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled)
{
NSLog(@"email cancelled");
}
else if (result == MessageComposeResultSent)
{
NSLog(@"email sent");
}
else
{
NSLog(@"email failed");
}
}
遇到的情况,封装成开放平台,发短信界面在我自己的手机弹不出,最后stackoverflow上一句重启手机,结果真的解决了
网友评论