zoukankan      html  css  js  c++  java
  • 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 }         
  • 相关阅读:
    ultraedit 窗口布局
    Oracle之Char VarChar VarChar2
    Python之pickle
    Python之xpath
    Python常用数据结构之heapq模块
    Python实现排序算法之快速排序
    Python常用数据结构之collections模块
    New York is 3 hours ahead of California
    leetcode978
    leetcode979
  • 原文地址:https://www.cnblogs.com/chuang/p/2831981.html
Copyright © 2011-2022 走看看