邮件、短信分享 推荐、电话

本文介绍如何在iOS应用中实现短信和邮件的分享功能,并提供了具体的代码示例。此外,还介绍了如何通过URL Scheme打开外部应用及判断该应用是否已安装的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分享前首先引入#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"]]];




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值