• IOS使用MessageUI Framework 发送短信息


    使用MessageUI Framework 中的 MFMessageComposeViewController 发送短信息,另外其中的MFMailComposeViewController用于发送邮件。使用非常简单:

    1. 导入框架:MessageUI.framework
    2. 添加协议:<MFMessageComposeViewControllerDelegate>
    3. #import <MessageUI/MessageUI.h>
     
     1 //判断当前设备是否可以发送短信息
     2 if([MFMessageComposeViewController canSendText])
     3 {
     4 
     5     MFMessageComposeViewController *mc = [[MFMessageComposeViewController alloc] init];
     6         //设置委托
     7     mc.messageComposeDelegate = self;
     8        //短信内容
     9     mc.body = @"nihao";
    10         //短信接收者,可设置多个
    11     mc.recipients = [NSArray arrayWithObject:@"10086",nil];
    12         
    13     [self presentModalViewController:mc animated:YES];
    14     [mc release];
    15 }
    16 else
    17 {
    18     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error",
    19                                     message:@"The current device can not send SMS"
    20                                     delegate:nil
    21                                     cancelButtonTitle:"OK",
    22                                     otherButtonTitles:nil];
    23     [alert show];
    24     [alert release];
    25 }
    26 
    27 
    28 #pragma mark -
    29 #pragma mark MFMessageComposeViewControllerDelegate
    30 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    31 {
    32     switch(result)
    33     {
    34         case MessageComposeResultCancelled:
    35             ...
    36         case MessageComposeResultFailed:
    37             ...
    38         case MessageComposeResultSend:
    39             ...    
    40         default:
    41             ...
    42     }
    43 }         
  • 相关阅读:
    基础操作
    需要注意
    简单操作
    git指令-版本回退
    设计模式-代理模式
    在idea下遇到的问题汇总
    maven笔记--持续更新
    poi简介
    Win10添加右键在此处打开命令行
    Ajax&Json案例
  • 原文地址:https://www.cnblogs.com/chuang/p/2831981.html
Copyright © 2020-2023  润新知