1
내 응용 프로그램에서 전자 메일 기능을 구현하려고합니다. 헤더 및 MFMailComposeViewControllerDelegate 프로토콜과 함께 MessageUI- 프레임 워크를 추가했지만 문제가 발생했습니다. 여기에 내 코드 :메일 응용 프로그램이 시작되지 않습니다!
- (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];
}
하지만 난 메일 버튼을 클릭하면 다음 applictaion은 종료하고로드를 시작합니다. 그것은 분명한 가치를 저장할 수 없다고 말했습니다 !!
setSubject-method를 사용하여 제목과 메시지 본문을 설정합니다. MFMailComposeViewController * emailDialog = [[MFMailComposeViewController alloc] init]; emailDialog.mailComposeDelegate = 자기; [emailDialog setSubject : @ "내 인라인 이미지 문서"]; [emailDialog setMessageBody : emailBody isHTML : 예]; \t [self presentModalViewController : emailDialog animated : YES]; [emailDialog release]; [emailBody release]; – Ketan
MFMailComposeViewController * mailController = [[[MFMailComposeViewController alloc] init] autorelease]; \t [mailController setMessageBody : @ "내 메일을 보낼 수 있습니다"isHTML : NO]; \t mailController.mailComposeDelegate = self; \t [self presentModalViewController : mailController animated : YES] – Ketan
이게 뭐야? 왜 메일 컴 포머의 두 가지 경우를 제시하고 있습니까? – visakh7