1

我想发送带有附件的邮件。在我的应用程序中,我为邮件功能创建了一个单独的类,在 rootViewController 中我有按钮Email It。当我单击它时,我的邮件功能必须被调用,但它没有。

  MFMailViewController *controller = [[MFMailViewController alloc] initWithNibName:"MFMailViewController" bundle:nil];                


[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];

之后我知道我不能像这样使用邮件功能。谁能帮我找到这个

4

3 回答 3

0

在 MFMailViewController 类中创建一个实例方法,其中包含一些参数,如字典或 NSArray

当您单击 Email it 按钮时,您正在创建 MFMailViewController 的对象,然后使用控制器对象调用实例方法并将参数或信息传递给。然后将其视图推送到导航。

#import <Foundation/Foundation.h>

@interface MFMailViewController : NSObject

{}

-(void)sendEmail:(NSMutableDictionary*)withData;

@end
#import "MFMailViewController.h"

@implementation MFMailViewController

-(void)sendEmail:(NSMutableDictionary*)withData;
{
    //definition goes here.................

}
@end

MFMailViewController *controller = [[MFMailViewController alloc] initWithNibName:"MFMailViewController" bundle:nil];                

[controller sendEmail:withData];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];
于 2012-04-23T10:33:24.690 回答
0

它不是 MFMailViewController,它的MFMailComposeViewController. 请浏览此Apple 参考以获取更多详细信息。

这是一个示例代码

if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
if(mailController!=nil) {
        mailController.mailComposeDelegate = self;
            [mailController setSubject:urSubject];
            [mailController setMessageBody:urBody isHTML:NO];
            [mailController addAttachmentData:urData mimeType:type fileName:urfileName];
}
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
于 2012-04-23T10:55:45.977 回答
0

很简单,您想在哪里发送邮件只需在您的方法中定义此代码.....但首先在您的 viewController 委托的 .h 文件中定义委托MFMailComposeViewControllerDelegate ,然后在按钮单击方法中编写此代码......

       MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
        controller.mailComposeDelegate = self;
        [controller setToRecipients:@"Recipients Name"];
        [controller setSubject:@"your subject"];
        [controller setMessageBody:@"Your Text Here for Mail" isHTML:YES]; 
        if (controller)
        {
            [self presentModalViewController:controller animated:YES];
            [controller release];
        }

然后你可以在你的ViewController.m文件中粘贴下面的mailComposerDelegate方法.....

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error;
{
    if (result == MFMailComposeResultSent) {
        NSLog(@"Mail Sent");
    }

    [self dismissModalViewControllerAnimated:YES];

}
于 2012-04-23T11:06:48.320 回答