• 调用系统的短信和发送邮件功能,实现短信分享邮件分享


    导入MessageUI.framework

    .h文件中#import <MessageUI/MessageUI.h>

    #import<MessageUI/MFMailComposeViewController.h>

    实现 MFMailComposeViewControllerDelegate, 

    MFMessageComposeViewControllerDelegate

    .m 文件

    //邮件

    -(void)showMailPicker {

       Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

        

    if (mailClass !=nil) {

            if ([mailClass canSendMail]) {

    [selfdisplayMailComposerSheet];

    }else{

                UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@""message:@"设备不支持邮件功能" delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];

                [alert show];

                [alert release];

            }

        }else{

            

        }

        

    }

    -(void)displayMailComposerSheet 

    {

    MFMailComposeViewController *picker = [[MFMailComposeViewControlleralloc] init];

       

    picker.mailComposeDelegate =self;

    [pickersetSubject:@"文件分享"];

    // Set up recipients

    NSArray *toRecipients = [NSArrayarrayWithObject:@"first@qq.com"]; 

    NSArray *ccRecipients = [NSArrayarrayWithObjects:@"second@qq.com",@"third@qq.com", nil]; 

    NSArray *bccRecipients = [NSArrayarrayWithObject:@"fourth@qq.com"]; 

        

    [pickersetToRecipients:toRecipients];

    [pickersetCcRecipients:ccRecipients];

    [pickersetBccRecipients:bccRecipients];

    //发送图片附件

    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];

    //NSData *myData = [NSData dataWithContentsOfFile:path];

    //[picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy.jpg"];

    //发送txt文本附件

    //NSString *path = [[NSBundle mainBundle] pathForResource:@"MyText" ofType:@"txt"];

    //NSData *myData = [NSData dataWithContentsOfFile:path];

    //[picker addAttachmentData:myData mimeType:@"text/txt" fileName:@"MyText.txt"];

    //发送doc文本附件 

    //NSString *path = [[NSBundle mainBundle] pathForResource:@"MyText" ofType:@"doc"];

    //NSData *myData = [NSData dataWithContentsOfFile:path];

    //[picker addAttachmentData:myData mimeType:@"text/doc" fileName:@"MyText.doc"];

    //发送pdf文档附件

    /*

    NSString *path = [[NSBundlemainBundle] pathForResource:@"CodeSigningGuide"ofType:@"pdf"];

    NSData *myData = [NSDatadataWithContentsOfFile:path];

    [pickeraddAttachmentData:myData mimeType:@"file/pdf"fileName:@"rainy.pdf"];

    */

    // Fill out the email body text

    NSString *emailBody =[NSStringstringWithFormat:@"我分享了文件给您,地址是%@",address] ;

    [pickersetMessageBody:emailBody isHTML:NO];

    [selfpresentModalViewController:picker animated:YES];

    [pickerrelease];

    }

    - (void)mailComposeController:(MFMailComposeViewController*)controller 

              didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

    // Notifies users about errors associated with the interface

    switch (result)

    {

    caseMFMailComposeResultCancelled:

    NSLog(@"Result: Mail sending canceled");

    break;

    caseMFMailComposeResultSaved:

               NSLog(@"Result: Mail saved");

    break;

    caseMFMailComposeResultSent:

    NSLog(@"Result: Mail sent");

    break;

    caseMFMailComposeResultFailed:

    NSLog(@"Result: Mail sending failed");

    break;

    default:

    NSLog(@"Result: Mail not sent");

    break;

    }

    [selfdismissModalViewControllerAnimated:YES];

    }

    //短信

    -(void)showSMSPicker{

       Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

        if (messageClass != nil) { 

       // Check whether the current device is configured for sending SMS messages

            if ([messageClass canSendText]) {

            [selfdisplaySMSComposerSheet];

            }

            else {

                UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@""message:@"设备不支持短信功能" delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];

                [alert show];

                [alert release];

                

            }

        }

        else {

            }

     }

    -(void)displaySMSComposerSheet

    {

       MFMessageComposeViewController *picker = [[MFMessageComposeViewControlleralloc] init];

    picker.messageComposeDelegate =self;

    NSString *smsBody =[NSStringstringWithFormat:@"我分享了文件给您,地址是%@",address] ;

        picker.body=smsBody;

    [selfpresentModalViewController:picker animated:YES];

    [pickerrelease];

    }

  • 相关阅读:
    python中list/tuple/dict/set的区别
    jquery修改ajax的header的字段origin方法,均被浏览器拒绝
    js判断上传文件的大小、类型、修改日期等信息
    js调试方法
    sqlmapapi的跨域访问Access-Control-Allow-Origin:*;ajax
    flask的文件上传和下载
    flask中的g、add_url_rule、send_from_directory、static_url_path、static_folder的用法
    python读写csv时中文乱码问题解决办法
    css中!important的作用
    项目经验——Sql server 数据库的备份和还原____还原数据库提示“介质集有2个介质簇,但只提供了1个。必须提供所有成员” .
  • 原文地址:https://www.cnblogs.com/xiaoyuaixiami/p/5217641.html
Copyright © 2020-2023  润新知