iOS 实用功能汇总(2)

1.打电话

1.第一种方法

这种方法在iOS8上测试的是不会出现弹框,直接进入到拨打电话界面,结束通话后会回到App界面。先跳出程序再进入到到系统的打电话程。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"10010"]]];

2.第二种方法(慎用)

这种方法提交审核的时候,可能会被拒,所以慎用。。。最好不用。。。

这种方法会出现弹框,结束通话后会回到App界面。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",@"10010"]]];

3.第三种方法

这种方法也会有弹框,结束通话后回到App界面,这种较第一种的区别在于: 一直都在自己的app中运行,没有出去过。

NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"10010"];
    UIWebView *callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [[UIApplication sharedApplication].keyWindow addSubview:callWebview];

发短信

需要导入MessageUI框架,#import <MessageUI/MessageUI.h>

if (![MFMessageComposeViewController canSendText]) return;
MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];

    // 设置短信内容(这里可以设置短信内容,也可以不设置)
    //vc.body = @"Hello!";

    // 设置收件人列表(这里可以指定收件人,也可以不设置)
    //vc.recipients = @[@"10010", @"10086"];

    // 设置代理
    vc.messageComposeDelegate = self;

    // 显示控制器
    [self presentViewController:vc animated:YES completion:nil];

还要实现代理方法MFMessageComposeViewControllerDelegate:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

    // 关闭短信界面
    [controller dismissViewControllerAnimated:YES completion:nil];
    if (result == MessageComposeResultCancelled) {
        NSLog(@"取消发送");
    } else if (result == MessageComposeResultSent) {
        NSLog(@"已经发出");
    } else {

        NSLog(@"发送失败");
    }
}

发邮件

和发短信一样,只不过是MFMailComposeViewController

/ 不能发邮件
if (![MFMailComposeViewController canSendMail]) return;

MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];

// 设置邮件主题
[vc setSubject:@"Hello"];
// 设置邮件内容
[vc setMessageBody:@"How are you?" isHTML:NO];
// 设置收件人列表
[vc setToRecipients:@[@"66666@qq.com"]];
// 设置抄送人列表
[vc setCcRecipients:@[@"66666@qq.com"]];
// 设置密送人列表
[vc setBccRecipients:@[@"66666@qq.com"]];

// 添加附件(一张图片)
UIImage *image = [UIImage imageNamed:@"pic.jpeg"];
NSData *data = UIImageJPEGRepresentation(image, 0.5);
[vc addAttachmentData:data mimeType:@"image/jepg" fileName:@"pic.jpeg"];

// 设置代理
vc.mailComposeDelegate = self;
// 显示控制器
[self presentViewController:vc animated:YES completion:nil];

同样实现代理:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    // 关闭邮件界面
    [controller dismissViewControllerAnimated:YES completion:nil];

    if (result == MFMailComposeResultCancelled) {
        NSLog(@"取消发送");
    } else if (result == MFMailComposeResultSent) {
        NSLog(@"已经发出");
    } else {
        NSLog(@"发送失败");
    }
}

跳转AppStore

NSString *str = [NSString stringWithFormat:
                 @"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值