zoukankan      html  css  js  c++  java
  • 调用系统的短信和发送邮件功能,实现短信分享邮件分享

    导入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];

    }

  • 相关阅读:
    BZOJ 2956: 模积和
    BZOJ 1113: [Poi2008]海报PLA
    停课刷题总结-给自己一点鼓励吧
    BZOJ 2751: [HAOI2012]容易题(easy)
    Vijos 1100 加分二叉树
    BZOJ 1756: Vijos1083 小白逛公园
    BZOJ 1709: [Usaco2007 Oct]Super Paintball超级弹珠
    BZOJ 1652: [Usaco2006 Feb]Treats for the Cows
    BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
    BZOJ 1631: [Usaco2007 Feb]Cow Party
  • 原文地址:https://www.cnblogs.com/xiaoyuaixiami/p/5217641.html
Copyright © 2011-2022 走看看