zoukankan      html  css  js  c++  java
  • iOS程序内发短信

    1、程序外发短信

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10086"]];
    

      

    2、程序内发短信,发完短信自动返回应用

      (1)首先导入框架MessageUI.framework

      (2) 引入头文件 #import <MessageUI/MessageUI.h>

      (3) 实现代理方法 <MFMessageComposeViewControllerDelegate, UINavigationControllerDelegate>

    3、直接上代码

    - (void)showMessageView{
        
        if ([MFMessageComposeViewController canSendText]) {
            
            MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
            
            controller.recipients = [NSArray arrayWithObject:@"10086"];
            
            controller.body = @"测试发短信";
            
            controller.messageComposeDelegate = self;
            
             [self presentViewController:controller animated:YES completion:nil];
            
            [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];
        }else{
            
            [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
        }
    }
    

      

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
        
        [controller dismissViewControllerAnimated:YES completion:nil];
        
        switch (result) {
            case MessageComposeResultCancelled:
                [self alertWithTitle:@"提示信息" msg:@"发送取消"];
                break;
                
            case MessageComposeResultFailed:
                [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];  
        
    }
    

      

  • 相关阅读:
    JAVAWEB进行PC支付宝支付
    SpringBoot 设置请求字符串格式为UTF-8
    SpringBoot 处理跨域请求问题
    Python 包制作
    F5 开发
    CentOS7 部署nfs服务
    Debian 9 部分快捷键失效问题
    Win10提示 该文件没有与之关联的程序来执行操作
    Debian 9 编译Python
    debian 9 安装远程桌面
  • 原文地址:https://www.cnblogs.com/h-tao/p/5274891.html
Copyright © 2011-2022 走看看