zoukankan      html  css  js  c++  java
  • 发送指内容的短信

     #import "ViewController.h"

    #import <MessageUI/MessageUI.h>

     

    @interface ViewController ()<MFMessageComposeViewControllerDelegate> 

    @end

     

    @implementation ViewController

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

    {

        if ([MFMessageComposeViewController canSendText]) {

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

            controller.recipients = [NSArray arrayWithObject:@"13888888888"];//指定发送人

            controller.body = @"发送短信验证";//指定发送内容

            controller.messageComposeDelegate = self;//设置代理

            [self presentViewController:controller animated:YES completion:^{

                //修改短信界面标题

                [[[[controller  viewControllers]lastObject]navigationItem ]setTitle:@"修改短信界面"];

            }];

        }else{

            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"警告" message:@"该设备不支持发送" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *action = [UIAlertAction actionWithTitle:@"acton" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                return ;

            }];

            [alertVC addAction:action];

            [self presentViewController:alertVC animated:YES completion:nil];

        }

    }

     

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

    {

        [controller dismissViewControllerAnimated:NO completion:nil];

           switch ( result ) {

            case MessageComposeResultCancelled:

            {

                //click cancel button

                NSLog(@"取消发送");

            }

                break;

            case MessageComposeResultFailed:// send failed

            {

                NSLog(@"发送失败");

            }

                break;

            case MessageComposeResultSent:

            {

                //do something

                NSLog(@"已发送出去了");

            }

                break;

            default:

                break;

        }

    }

     

    @end

  • 相关阅读:
    gulp常用插件之gulp-plumber使用
    gulp常用插件之gulp-load-plugins使用
    gulp常用插件之yargs使用
    ql自动化测试之路-概述篇
    ql的python学习之路-day11
    ql的python学习之路-day10
    ql的python学习之路-day9
    python实现简易工资管理系统(Salary Manage)源码
    python控制台实现打印带颜色的字体
    ql的python学习之路-day8
  • 原文地址:https://www.cnblogs.com/sunflower-lhb/p/5555735.html
Copyright © 2011-2022 走看看