我想发送带附件的邮件。在我的应用程序中,我为mail函数创建了一个单独的类,在rootViewController中我有按钮通过电子邮件发送。当我点击它我的邮件功能必须被调用,但它没有。
MFMailViewController *controller = [[MFMailViewController alloc] initWithNibName:"MFMailViewController" bundle:nil];
[[self navigationController] pushViewController:viewController animated:YES];
[viewController release];
之后我知道我不能使用这样的邮件功能。任何人都可以帮我找到这个
答案 0 :(得分:0)
在MFMailViewController类中创建一个实例方法,其中包含一些参数,如字典或NSArray
当您点击Email it按钮时,您正在创建MFMailViewController的对象,然后使用控制器对象调用实例方法并将参数或信息传递给。 然后推动它的导航视图。
#import <Foundation/Foundation.h>
@interface MFMailViewController:NSObject
{}
- (无效)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];
答案 1 :(得分:0)
它不是MFMailViewController,它是MFMailComposeViewController
。请仔细阅读Apple reference以获取更多详细信息。
以下是示例代码
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];
}
答案 2 :(得分: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];
}