• 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 }         
  • 相关阅读:
    python os.path
    ant的基本说明
    gcc的基本使用方法
    java逻辑运算符小节
    awk 简单教程
    推荐:恢复Ext3下被删除的文件
    python读取excel
    ant的简明教程,后面运行写的不错
    WinForm中快捷键与组合按键的设置
    InstallShield 2010集成.net Framework 4的安装包制作
  • 原文地址:https://www.cnblogs.com/chuang/p/2831981.html
Copyright © 2020-2023  润新知