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];  
        
    }
    

      

  • 相关阅读:
    POJ 2342.Anniversary party-树形dp
    Codeforces Round #363 (Div. 2) A、B、C
    Codeforces Beta Round #17 D.Notepad 指数循环节
    hdu 5920 Wool 思路
    hdu 5719 Arrange 贪心
    hdu 5718 Oracle 高精度
    hiho #1332 : 简单计算器 栈+递归
    UESTC 1074 秋实大哥搞算数 栈模拟
    cdoj 1329 卿学姐与魔法 优先队列
    cdoj 1324 卿学姐与公主 线段树裸题
  • 原文地址:https://www.cnblogs.com/h-tao/p/5274891.html
Copyright © 2011-2022 走看看