码迷,mamicode.com
首页 > 移动开发 > 详细

ios 调用打电话,发短信的功能

时间:2015-07-30 15:01:07      阅读:340      评论:0      收藏:0      [点我收藏+]

标签:ios   发短信 打电话   

首先:

Frameworks中要引入MessageUI.framework 

#import <MessageUI/MessageUI.h>
添加协议:
<MFMessageComposeViewControllerDelegate>

之后看代码:

有两种短信调用,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 调用打电话,发短信的功能

标签:ios   发短信 打电话   

原文地址:http://blog.csdn.net/wenhaiwang/article/details/47148567

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!