1

iOS アプリケーションから送信された電子メールに、ローカルに保存された HTML ページを添付することはできますか??

正しい mimeType は何ですか?

編集

これは動作しない私のコードです。ローカル html ファイルの添付を妨げている問題がどこにあるかを指摘してください。

-(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];
}
4

3 に答える 3

0

なぜそれが問題になるのかわかりません。

mimetypeは'text/html'です。ここを見てください:

http://reference.sitepoint.com/html/mime-types-full

于 2012-11-10T12:18:00.890 に答える
0

@Shymaa Othman使用しているMIMEタイプは正しいです.htmlを正しく検索し、NSDataがnullではないことを確認したかどうかを確認する必要があります..?そうでない場合は、メールに添付する前にこのコードを試してください。

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

NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
于 2012-11-10T15:07:53.043 に答える
0

isHTML = YESでMessageBodyを設定し、さらにテキスト添付ファイルを追加すると機能します。

NSData *stringData = [textBody dataUsingEncoding:NSUTF8StringEncoding];
[mailer addAttachmentData:stringData
                 mimeType:@"text/plain"
                 fileName:@"text_file"];
于 2016-07-08T09:12:28.930 に答える