分享前首先引入#import <MessageUI/MessageUI.h>头文件遵守协议
<MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
短信分享
MFMessageComposeViewController *vc = [[MFMessageComposeViewControlleralloc]init];
// 设置短信内容
vc.body =@"短信内容";
// 设置收件人列表
vc.recipients =@[@"收件人1",@"收件人2"];
// 设置代理
vc.messageComposeDelegate = share;
share.age;
// 显示控制器
[share presentViewController:vcanimated:YEScompletion:nil];
// 当你取消发送短信的时候就会调用
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
邮件分享
// 不能发邮件
if (![MFMailComposeViewControllercanSendMail])return;
MFMailComposeViewController *vc = [[MFMailComposeViewControlleralloc]init];
// 设置邮件主题
[vc setSubject:@"sbject"];
// 设置邮件内容
[vc setMessageBody:@"body"isHTML:NO];
// 设置收件人列表
[vc setToRecipients:@[@"邮箱地址"]];
// 设置抄送人列表
[vc setCcRecipients:@[@"邮箱地址"]];
// 设置密送人列表
[vc setBccRecipients:@[@"邮箱地址"]];
// 添加附件
UIImage *image = [UIImageimageNamed:@"imageName];
NSData *data =UIImagePNGRepresentation(image);
[vc addAttachmentData:datamimeType:@"image/png"fileName:@"image.png"];
// 设置代理
// vc.mailComposeDelegate = self;
// // 显示控制器
// [self presentViewController:vc animated:YES completion:nil];
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
在应用的info选项中的URLTypes选项URL Schemes规定协议头 Identifier规定路径
这个应用的url:由 URL Schemes://Identifier平接成
NSString *urlStr = [NSStringstringWithFormat:@"%@://%@",p.customUrl,p.ID];
NSURL *url = [NSURLURLWithString:urlStr];
UIApplication *app = [UIApplicationsharedApplication];
if ([appcanOpenURL:url]) {//是否安装这个应用
//安装了这个应用
[[UIApplicationsharedApplication]openURL:url];
}else{//没有安装这个应用
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:p.url]];
}
//去Store 评分
NSString *appid = @"5*42";
NSString *str = [NSString stringWithFormat:
@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
客服电话:
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]];