zoukankan      html  css  js  c++  java
  • IOS 掉用系统发短信

    
    

    #import <MessageUI/MessageUI.h>

    MFMessageComposeViewControllerDelegate

    #pragma mark - 调用ios系统短信发送模块
    -(void)shareUseSMSWithMessage:(NSString *)message
    {
        Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
        if (messageClass != nil) {
            // Check whether the current device is configured for sending SMS messages
            if ([messageClass canSendText]) {
                MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
                picker.messageComposeDelegate = self;
                picker.body = message;
                [self.navigationController presentViewController:picker animated:YES completion:nil];
            }
            else {
                UIAlertView *canSend = [[UIAlertView alloc] initWithTitle:@"设备没有短信功能" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"关闭", nil];
                [canSend show];
            }
        }else{
            UIAlertView *visionAlert = [[UIAlertView alloc] initWithTitle:@"iOS版本过低,iOS4.0以上才支持程序内发送短信" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"关闭", nil];
            [visionAlert show];
        }
    }
    
    #pragma mark - MFMessageComposeViewControllerDelegate
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    {
        switch (result)
        {
            case MessageComposeResultCancelled:
                NSLog(@"Result: SMS sending canceled");
                break;
            case MessageComposeResultSent:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"短信发送成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
                NSLog(@"Result: SMS sent");
            }
                break;
            case MessageComposeResultFailed:
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"短信发送失败" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
            }
                break;
            default:
                NSLog(@"Result: SMS not sent");
                break;
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }
  • 相关阅读:
    解决linux下主机名变bogon的问题
    如何压缩虚拟机文件
    Linux shell crontab expdp 定时任务逻辑备份 定时删除旧文件
    .NET ramework 4.0安装失败
    Oracle数据库密码过期
    MySQL max_allowed_packet设置及问题
    WPF 异步执行
    win8 无法显示桌面,运行explorer.exe 提示 0xc0000018 异常 解决办法
    最全的Spark基础知识解答
    数据处理包plyr和dplyr包的整理
  • 原文地址:https://www.cnblogs.com/joesen/p/3633834.html
Copyright © 2011-2022 走看看