Iphone “的用户界面”;新讯息;邮件应用程序?

Iphone “的用户界面”;新讯息;邮件应用程序?,iphone,Iphone,如何在iPhone中实现邮件应用程序的“新消息”UI。使用该类。使用该类。不要担心将邮件集成到应用程序中的UI。一切都将由MFMailComposeViewController框架负责。添加此框架并编写以下代码 #import <MessageUI/MessageUI.h> @interface ViewReminderViewController_iPhone : UIViewController <MFMailCompose

如何在iPhone中实现邮件应用程序的“新消息”UI。

使用该类。

使用该类。

不要担心将邮件集成到应用程序中的UI。一切都将由MFMailComposeViewController框架负责。添加此框架并编写以下代码

    #import <MessageUI/MessageUI.h>

    @interface ViewReminderViewController_iPhone : UIViewController
                <MFMailComposeViewControllerDelegate>
    {
    UiButton *mailButton;
    }
    - (IBAction)EmailButton:(id)sender;
    @end

    @implementation ViewController
    - (IBAction)EmailButton:(id)sender
    {

        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
        [picker setSubject:@"Your EMail Subject"];

        //SET UP THE RECIPIENTS (or leave not set)
        //NSArray *toRecipients = [NSArray arrayWithObjects:@"first@example.com", nil];
        //[picker setToRecipients:toRecipients];

        //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
        //[picker setCcRecipients:ccRecipients];

        //NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com", nil];
        //[picker setBccRecipients:bccRecipients];

        //ATTACH FILE

        NSString *path;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MediaFiles"];
        path = [path stringByAppendingPathComponent:MyFileName];

        NSLog(@"Attaching file: %@", path);

        if ([[NSFileManager defaultManager] fileExistsAtPath:path])     //Does file exist?
        {
                NSLog(@"File exists to attach");

                NSData *myData = [NSData dataWithContentsOfFile:path];

                [picker addAttachmentData:myData mimeType:@"application/octet-stream"
                                 fileName:@"DesredFileName.mov"];

        }

        //CREATE EMAIL BODY TEXT
        NSString *emailBody = @"Your Email Body";
        [picker setMessageBody:emailBody isHTML:NO];

        //PRESENT THE MAIL COMPOSITION INTERFACE
        [self presentModalViewController:picker animated:YES];
        [picker release];

    }

 Delegate To Clear Compose Email View Controller


    - (void)mailComposeController:(MFMailComposeViewController *)controller
              didFinishWithResult:(MFMailComposeResult)result
                            error:(NSError *)error
    {

        [self dismissModalViewControllerAnimated:YES];      //Clear the compose email view controller
    }
#导入
@界面视图提醒服务控制器\u iPhone:UIViewController
{
UiButton*邮件按钮;
}
-(iAction)EmailButton:(id)发件人;
@结束
@实现视图控制器
-(iAction)EmailButton:(id)发件人
{
MFMailComposeViewController*选择器=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
[picker setSubject:@“您的电子邮件主题”];
//设置收件人(或保留未设置)
//NSArray*toRecipients=[NSArray arrayWithObjects:@”first@example.com“,无];
//[picker setToRecipients:toRecipients];
//NSArray*ccRecipients=[NSArray arrayWithObjects:@”second@example.com", @"third@example.com“,无];
//[选择器设置ccRecipients:ccRecipients];
//NSArray*BCCreciients=[NSArray arrayWithObjects:@”four@example.com“,无];
//[选取者/接收者:b委托人];
//附加文件
NSString*路径;
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
path=[[paths objectAtIndex:0]stringByAppendingPathComponent:@“MediaFiles”];
path=[path stringByAppendingPathComponent:MyFileName];
NSLog(@“附加文件:%@”,路径);
如果([[NSFileManager defaultManager]fileExistsAtPath:path])//文件是否存在?
{
NSLog(@“要附加的文件已存在”);
NSData*myData=[NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@“应用程序/八位字节流”
文件名:@“DesredFileName.mov”];
}
//创建电子邮件正文文本
NSString*emailBody=@“您的电子邮件正文”;
[picker setMessageBody:emailBody isHTML:NO];
//显示邮件合成界面
[自我呈现ModalviewController:picker动画:是];
[选择器释放];
}
委托以清除撰写电子邮件视图控制器
-(无效)mailComposeController:(MFMailComposeViewController*)控制器
didFinishWithResult:(MFMailComposer结果)结果
错误:(n错误*)错误
{
[自我解除ModalViewController激活:是];//清除撰写电子邮件视图控制器
}

不必担心将邮件集成到应用程序中的UI。一切都将由MFMailComposeViewController框架负责。添加此框架并编写以下代码

    #import <MessageUI/MessageUI.h>

    @interface ViewReminderViewController_iPhone : UIViewController
                <MFMailComposeViewControllerDelegate>
    {
    UiButton *mailButton;
    }
    - (IBAction)EmailButton:(id)sender;
    @end

    @implementation ViewController
    - (IBAction)EmailButton:(id)sender
    {

        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
        [picker setSubject:@"Your EMail Subject"];

        //SET UP THE RECIPIENTS (or leave not set)
        //NSArray *toRecipients = [NSArray arrayWithObjects:@"first@example.com", nil];
        //[picker setToRecipients:toRecipients];

        //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
        //[picker setCcRecipients:ccRecipients];

        //NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com", nil];
        //[picker setBccRecipients:bccRecipients];

        //ATTACH FILE

        NSString *path;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MediaFiles"];
        path = [path stringByAppendingPathComponent:MyFileName];

        NSLog(@"Attaching file: %@", path);

        if ([[NSFileManager defaultManager] fileExistsAtPath:path])     //Does file exist?
        {
                NSLog(@"File exists to attach");

                NSData *myData = [NSData dataWithContentsOfFile:path];

                [picker addAttachmentData:myData mimeType:@"application/octet-stream"
                                 fileName:@"DesredFileName.mov"];

        }

        //CREATE EMAIL BODY TEXT
        NSString *emailBody = @"Your Email Body";
        [picker setMessageBody:emailBody isHTML:NO];

        //PRESENT THE MAIL COMPOSITION INTERFACE
        [self presentModalViewController:picker animated:YES];
        [picker release];

    }

 Delegate To Clear Compose Email View Controller


    - (void)mailComposeController:(MFMailComposeViewController *)controller
              didFinishWithResult:(MFMailComposeResult)result
                            error:(NSError *)error
    {

        [self dismissModalViewControllerAnimated:YES];      //Clear the compose email view controller
    }
#导入
@界面视图提醒服务控制器\u iPhone:UIViewController
{
UiButton*邮件按钮;
}
-(iAction)EmailButton:(id)发件人;
@结束
@实现视图控制器
-(iAction)EmailButton:(id)发件人
{
MFMailComposeViewController*选择器=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
[picker setSubject:@“您的电子邮件主题”];
//设置收件人(或保留未设置)
//NSArray*toRecipients=[NSArray arrayWithObjects:@”first@example.com“,无];
//[picker setToRecipients:toRecipients];
//NSArray*ccRecipients=[NSArray arrayWithObjects:@”second@example.com", @"third@example.com“,无];
//[选择器设置ccRecipients:ccRecipients];
//NSArray*BCCreciients=[NSArray arrayWithObjects:@”four@example.com“,无];
//[选取者/接收者:b委托人];
//附加文件
NSString*路径;
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
path=[[paths objectAtIndex:0]stringByAppendingPathComponent:@“MediaFiles”];
path=[path stringByAppendingPathComponent:MyFileName];
NSLog(@“附加文件:%@”,路径);
如果([[NSFileManager defaultManager]fileExistsAtPath:path])//文件是否存在?
{
NSLog(@“要附加的文件已存在”);
NSData*myData=[NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@“应用程序/八位字节流”
文件名:@“DesredFileName.mov”];
}
//创建电子邮件正文文本
NSString*emailBody=@“您的电子邮件正文”;
[picker setMessageBody:emailBody isHTML:NO];
//显示邮件合成界面
[自我呈现ModalviewController:picker动画:是];
[选择器释放];
}
委托以清除撰写电子邮件视图控制器
-(无效)mailComposeController:(MFMailComposeViewController*)控制器
didFinishWithResult:(MFMailComposer结果)结果
错误:(n错误*)错误
{
[自我解除ModalViewController激活:是];//清除撰写电子邮件视图控制器
}