ios 打电话 发短信

打电话

第一种:利用私有API,appStore不合法

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]]

第二种:UIWebView加载电话,这种是合法的,可以上App Store的

UIWebView*callWebview =[[UIWebView alloc] init];  
NSURL *telURL =[NSURL URLWithString:@"tel:10010"];  
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];  
//记得添加到view上  
[self.view addSubview:callWebview]; 

 

 

发信息:

 

第一种:利用私有API

      [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"]];//发短信  

第二种:系统提供的控制器MFMessageComposeViewController

    1.控制器实现MFMessageComposeViewController的代理方法MFMessageComposeViewControllerDelegate

      

@interface DemoViewController : UIViewController <MFMessageComposeViewControllerDelegate>  
  
@end 

 2、调用MFMessageComposeViewController,同时实现协议MFMessageComposeViewControllerDelegate。

 

- (void)showMessageView  
{  
      
    if( [MFMessageComposeViewController canSendText] ){  
          
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease];  
          
        controller.recipients = [NSArray arrayWithObject:@"10010"];       
        controller.body = @"测试发短信";          
        controller.messageComposeDelegate = self;  
  
        [self presentModalViewController:controller animated:YES];  
          
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题  
    }else{  
          
        [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];          
    }      
}  


- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{  
      
    [controller dismissModalViewControllerAnimated:NO];//关键的一句   不能为YES  
      
    switch ( result ) {  
              
        case MessageComposeResultCancelled:  
  
            [self alertWithTitle:@"提示信息" msg:@"发送取消"];   
            break;  
        case MessageComposeResultFailed:// send failed  
            [self alertWithTitle:@"提示信息" msg:@"发送成功"];   
            break;  
        case MessageComposeResultSent:  
            [self alertWithTitle:@"提示信息" msg:@"发送失败"];   
            break;  
        default:  
            break;   
    }  
}  


- (void) alertWithTitle:(NSString *)title msg:(NSString *)msg {  
  
      
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title  
           message:msg  
           delegate:self  
           cancelButtonTitle:nil  
           otherButtonTitles:@"确定", nil];  
                           
   [alert show];  
                   
}  

 

 

参考:http://blog.csdn.net/xyz_lmn/article/details/8968209

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。