2012-11-10 3 views
1

iOS 응용 프로그램에서 보내는 이메일에 로컬 저장된 HTML 페이지를 첨부 할 수 있습니까 ??iOS - 이메일에 로컬 HTML 페이지 첨부하기

올바른 mimeType은 무엇입니까?

편집

이 로컬 HTML 파일의 부착을 방지 할 문제이고, 밖으로 poit하시기 바랍니다 작동하지 않습니다 내 코드입니다. 이 문제가 될 이유

-(IBAction)share:(id)sender{ 


NSString *btn_title = [sender titleForState:(UIControlStateNormal)]; 

if ([btn_title isEqualToString: @"fb"]) { 


}else if ([btn_title isEqualToString: @"tw"]){ 


}else if ([btn_title isEqualToString: @"email"]){ 

    if ([MFMailComposeViewController canSendMail]) 
    { 
     MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 
     mailer.mailComposeDelegate = self; 
     [mailer setSubject:@""]; 
     NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil]; 
     [mailer setToRecipients:toRecipients]; 

     NSString *emailBody = @""; 

     NSError * error = nil; 
     NSData *htmlData = [NSData dataWithContentsOfFile:@"/hamla.html" options: NSMappedRead error: &error]; 

     [mailer addAttachmentData:htmlData mimeType:@"text/html" fileName:@"hamla"]; 

     [mailer setMessageBody:emailBody isHTML:NO]; 
     [self presentModalViewController:mailer animated:YES]; 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                 message:@"Your device doesn't support the composer sheet" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 
     [alert show]; 
    } 
} 

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the drafts folder."); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); 
      break; 
     default: 
      NSLog(@"Mail not sent."); 
      break; 
    } 
    // Remove the mail view 
    [self dismissModalViewControllerAnimated:YES]; 
} 

답변

0

@Shymaa 오스만 MIME 타입 유 correct.Just은 u는 u는 제대로 UR HTML을 찾기 및 null가 아닌있는 NSData를 받고 r에 있는지 확인해야 알 필요가있다하여 r에 .. : 여기를 보라? 메일에 첨부하기 전에이 코드를 사용해보십시오.

NSData NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"hamla" ofType:@"html"]; 

NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; 
0

isHTML = YES로 setMessageBody를 설정하고 텍스트 첨부 파일을 추가 할 때 작동합니다.

NSData *stringData = [textBody dataUsingEncoding:NSUTF8StringEncoding]; 
[mailer addAttachmentData:stringData 
       mimeType:@"text/plain" 
       fileName:@"text_file"]; 
관련 문제