iOS 拨打电话,发短信

一、拨打电话

1、拨打完电话回不到原来应用,会停留在通讯录,而且是直接拨打,不弹出提示
   NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",手机或电话号码(如@"13209877890")];
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
2、打完电话后还会回到原程序,会弹出提示
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",手机或电话号码(如@"13209877890")];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
3、回原程序(这里是telprompt),也会弹出提示
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",手机或电话号码(如:@"13209877890")];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]




二、发短信

1,程序外调用系统发短信。

     [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"sms://13888888888"]];

2,程序内调用系统发短信。第二种的好处是用户发短信之后还可以回到app。


连接地址:

http://worldligang.baijia.baidu.com/article/87026

    

1)导入MessageUI.framework,并引入头文件:

#import<MessageUI/MessageUI.h>

2)实现代理方法MFMessageComposeViewControllerDelegate

-(void)messageComposeViewController:(MFMessageComposeViewController*)controllerdidFinishWithResult:(MessageComposeResult)result

{

[selfdismissViewControllerAnimated:YEScompletion:nil];

switch(result){

caseMessageComposeResultSent:

//信息传送成功

break;

caseMessageComposeResultFailed:

//信息传送失败

break;

caseMessageComposeResultCancelled:

//信息被用户取消传送

break;

default:

break;

}

}

3)发送短信

-(void)showMessageView:(NSArray*)phonestitle:(NSString*)titlebody:(NSString*)body

{

if([MFMessageComposeViewControllercanSendText])

{

MFMessageComposeViewController*controller=[[MFMessageComposeViewControlleralloc]init];

controller.recipients=phones;

controller.navigationBar.tintColor=[UIColorredColor];

controller.body=body;

controller.messageComposeDelegate=self;

[selfpresentViewController:controlleranimated:YEScompletion:nil];

[[[[controllerviewControllers]lastObject]navigationItem]setTitle:title];//修改短信界面标题

}

else

{

UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@"提示信息"

message:@"该设备不支持短信功能"

delegate:nil

cancelButtonTitle:@"确定"

otherButtonTitles:nil,nil];

[alertshow];

}

}

参数phones:发短信的手机号码的数组,数组中是一个即单发,多个即群发。

4)调用发短信的方法

[selfshowMessageView:[NSArrayarrayWithObjects:@"13888888888",@"13999999999",nil]title:@"test"body:@"你是土豪么,么么哒"];



你可能感兴趣的:(拨打电话,发短信)