iOS中:最完善的:打电话和发短信

// 打电话合法:

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    UIWebView*callWebview =[[UIWebView alloc]init];

    NSURL *telURL =[NSURLURLWithString:@"tel:18679824696"];

    [callWebview loadRequest:[NSURLRequestrequestWithURL:telURL]];

    //记得添加到view上

    [self.view addSubview:callWebview];

   

}

 

// 发短信:

 

需要MessageUI.framework框架

遵守MFMessageComposeViewControllerDelegate协议

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self showMessageView];

}

 

-(void)showMessageView

{

   

    if( [MFMessageComposeViewControllercanSendText] ){

       

        MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc]init]; //autorelease];

       

        controller.recipients = [NSArrayarrayWithObject:@"18679824696"];

        controller.body =@"测试发短信";

        controller.messageComposeDelegate =self;

       

        [selfpresentModalViewController:controller animated:YES];

       

        [[[[controllerviewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题

    }else{

       

        [selfalertWithTitle:@"提示信息"msg:@"设备没有短信功能"];

    }

}

 

 

//MFMessageComposeViewControllerDelegate

 

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

   

    [controllerdismissModalViewControllerAnimated:NO];//关键的一句   不能为YES

   

    switch ( result ) {

           

        case MessageComposeResultCancelled:

           

            [selfalertWithTitle:@"提示信息"msg:@"发送取消"];

            break;

        case MessageComposeResultFailed:// sendfailed

            [selfalertWithTitle:@"提示信息"msg:@"发送成功"];

            break;

        case MessageComposeResultSent:

            [selfalertWithTitle:@"提示信息"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]; 

   

}

阅读更多
上一篇iOS数据持久化存储 (1)-- Plist 、归档、NSUserDefaults、NSFileManager
想对作者说点什么? 我来说一句

DemoEmailSMS

2016年07月15日 96KB 下载

没有更多推荐了,返回首页

关闭
关闭