Iphone 邮件应用程序未启动!
我正在尝试在我的应用程序中实现电子邮件的功能。我添加了MessageUI框架,以及header和MFMailComposeViewControllerDelegate协议,但我面临这个问题。这是我的密码:Iphone 邮件应用程序未启动!,iphone,Iphone,我正在尝试在我的应用程序中实现电子邮件的功能。我添加了MessageUI框架,以及header和MFMailComposeViewControllerDelegate协议,但我面临这个问题。这是我的密码: - (void)viewDidLoad { [super viewDidLoad]; if(isViewPushed == NO) { self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
- (void)viewDidLoad {
[super viewDidLoad];
if(isViewPushed == NO) {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self action:@selector(email)] autorelease];
}
}
-(void) email
{
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
[emailBody appendString:@"<p>type text here</p>"];
UIImage *emailImage = [UIImage imageNamed:@"20-gear2.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64.....,.......%@'></b></p>",imageData]];
[emailBody appendString:@"</body></html>"];
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:@"My Inline Image Document"];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
if(! [MFMailComposeViewController canSendMail])
{
UIAlertView *cantMailAlert = [[UIAlertView alloc]
initWithTitle:@"cant email"
message:@"nt able to send email"
delegate:NULL
cancelButtonTitle:@"ok"
otherButtonTitles:NULL];
[cantMailAlert show];
[cantMailAlert release];
return;
}
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
[mailController setMessageBody:@"can send my mail" isHTML:NO];
mailController.mailComposeDelegate = self;
[self presentModalViewController:mailController animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (error)
{
UIAlertView *cantMailAlert = [[UIAlertView alloc]
initWithTitle:@"mail error"
message: [error localizedDescription]
delegate:NULL
cancelButtonTitle:@"ok"
otherButtonTitles:NULL];
[cantMailAlert show];
[cantMailAlert release];
return;
}
NSString *resultString;
switch (result)
{
case MFMailComposeResultSent:
resultString = @"sent mail";
break;
case MFMailComposeResultSaved:
resultString = @"saved";
break;
case MFMailComposeResultCancelled:
resultString = @"cancel";
break;
case MFMailComposeResultFailed:
resultString = @"failed";
break;
}
if (resultString = @"saved")
{
NSString *msg = [NSString stringWithFormat:@"%@ at %@\n", resultString, [NSDate date]];
UIAlertView *MailAlert = [[UIAlertView alloc]
initWithTitle:@"status"
message: msg
delegate:NULL
cancelButtonTitle:@"ok"
otherButtonTitles:NULL];
[MailAlert show];
[MailAlert release];
return;
}
[controller dismissModalViewControllerAnimated:YES];
[controller release];
//[self email];
}
-(void)viewDidLoad{
[超级视图下载];
如果(isViewPushed==否){
self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
目标:自我行动:@selector(email)]autorelease];
}
}
-(无效)电子邮件
{
NSMutableString*emailBody=[[NSMutableString alloc]initWithString:@']retain];
[emailBody appendString:@“在此处键入文本””;
UIImage*emailImage=[UIImage ImageName:@“20-gear2.png”];
NSData*imageData=[NSData dataWithData:UIImagePNGRepresentation(emailImage)];
[emailBody appendString:[NSString stringWithFormat:@“”,imageData];
[emailBody appendString:@”“;
MFMailComposeViewController*emailDialog=[[MFMailComposeViewController alloc]init];
emailDialog.mailComposeDelegate=self;
[emailDialog setSubject:@“我的内联图像文档”];
[self-presentModalViewController:emailDialog动画:是];
[emailDialog发布];
如果(![MFMailComposeViewController可以发送邮件])
{
UIAlertView*cantMailAlert=[[UIAlertView alloc]
initWithTitle:@“无法发送电子邮件”
消息:@“nt无法发送电子邮件”
委托:NULL
取消按钮:@“确定”
OtherButtonTiles:NULL];
[cantMailAlert show];
[cantMailAlert发布];
回来
}
MFMailComposeViewController*mailController=[[MFMailComposeViewController alloc]init]autorelease];
[mailController setMessageBody:@“可以发送我的邮件”isHTML:NO];
mailController.mailComposeDelegate=self;
[自我呈现ModalViewController:mailController动画:是];
}
-(void)mailComposeController:(MFMailComposeViewController*)控制器未完成结果:(MFMailComposeResult)结果错误:(NSError*)错误
{
如果(错误)
{
UIAlertView*cantMailAlert=[[UIAlertView alloc]
initWithTitle:@“邮件错误”
消息:[错误本地化描述]
委托:NULL
取消按钮:@“确定”
OtherButtonTiles:NULL];
[cantMailAlert show];
[cantMailAlert发布];
回来
}
NSString*resultString;
开关(结果)
{
案例MFMailComposer结果已发送:
resultString=@“已发送邮件”;
打破
案例MFMailComposer结果已保存:
结果字符串=@“已保存”;
打破
案例MFMailComposer结果已取消:
结果字符串=@“取消”;
打破
案例MFMailComposer结果失败:
resultString=@“失败”;
打破
}
如果(结果字符串=@“已保存”)
{
NSString*msg=[NSString stringWithFormat:@“%@at%@\n”,结果字符串[NSDate date]];
UIAlertView*MailAlert=[[UIAlertView alloc]
initWithTitle:@“状态”
信息:msg
委托:NULL
取消按钮:@“确定”
OtherButtonTiles:NULL];
[MailAlert show];
[邮件警报发布];
回来
}
[controller dismissModalViewControllerAnimated:是];
[控制器释放];
//[自我电邮];
}
但当我点击邮件按钮时,applictaion终止并开始加载。上面说不能储存私密的价值 为什么在
viewDidLoad
中显示MFMailcomposeviewcontroller
的两个实例?为什么要创建两个对象,即emailDialog
和mailController
,并显示它们?使用setSubject方法设置标题和邮件正文。MFMailComposeViewController*emailDialog=[[MFMailComposeViewController alloc]init];emailDialog.mailComposeDelegate=self;[emailDialog setSubject:@“我的内联图像文档”];[emailDialog setMessageBody:emailBody isHTML:YES];[self-presentModalViewController:emailDialog动画:是];[emailDialog发布];[邮件正文发布];MFMailComposeViewController*mailController=[[MFMailComposeViewController alloc]init]autorelease];[mailController setMessageBody:@“可以发送我的邮件”isHTML:NO];mailController.mailComposeDelegate=self;[self-presentModalViewController:mailController:YES]这需要什么?你为什么要展示mailcomposer的两个实例?我已经删除了我创建的一个实例。bt m nt 2可以看到我插入的图像,