iPhone 应用内电子邮件

发布于 2024-10-21 06:02:02 字数 60 浏览 3 评论 0原文

我的应用程序发送电子邮件,但有没有办法将照片放在我的电子邮件中我发送的文本上方。有点像显示我的徽标的标题。

I have my application sending an email, but is there a way to put a photo in my email above the text i'm sending. Kind of like a header to display my logo.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫弦 2024-10-28 06:02:02
// Action for submenu Email Button
- (IBAction)emailButtonPressed {
[delegate playSound:@"Click_16"];

if (connectionStatus == YES) 
{

    if (maxCounter) 
    {
        NSString *filename = (NSString *)[self currentImageObject:kSerialKey AtIndex:imageCounter];

        NSString* documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

            // set up image data for email
        NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:filename];
        NSData *imageData = [NSData dataWithContentsOfFile:imageFile];

            // set up mail view controller for message
        MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
        if (controller != nil) 
        {
            controller.mailComposeDelegate = self;
            [controller setSubject:@"Email Subject"];
            [controller setMessageBody:@"Check out this picture" isHTML:NO];
            [controller addAttachmentData:imageData mimeType:@"image/png" fileName:filename];
            [self presentModalViewController:controller animated:YES];

        }

        [controller release];

    }

    else 
        [self genericAlert:@"There are no pictures to email."];

}

else
    [self genericAlert:@"You are not connected to the internet.  Please connect and try again."];

}

// email delegate method to dismiss window
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self becomeFirstResponder];
    [self dismissModalViewControllerAnimated:YES];
}
// Action for submenu Email Button
- (IBAction)emailButtonPressed {
[delegate playSound:@"Click_16"];

if (connectionStatus == YES) 
{

    if (maxCounter) 
    {
        NSString *filename = (NSString *)[self currentImageObject:kSerialKey AtIndex:imageCounter];

        NSString* documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

            // set up image data for email
        NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:filename];
        NSData *imageData = [NSData dataWithContentsOfFile:imageFile];

            // set up mail view controller for message
        MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
        if (controller != nil) 
        {
            controller.mailComposeDelegate = self;
            [controller setSubject:@"Email Subject"];
            [controller setMessageBody:@"Check out this picture" isHTML:NO];
            [controller addAttachmentData:imageData mimeType:@"image/png" fileName:filename];
            [self presentModalViewController:controller animated:YES];

        }

        [controller release];

    }

    else 
        [self genericAlert:@"There are no pictures to email."];

}

else
    [self genericAlert:@"You are not connected to the internet.  Please connect and try again."];

}

// email delegate method to dismiss window
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [self becomeFirstResponder];
    [self dismissModalViewControllerAnimated:YES];
}
再见回来 2024-10-28 06:02:02

当您使用 MFMailComposeViewController 附加图像时,它始终显示在消息底部(在文本下方,但在签名上方),并且在当前版本的框架中无法更改。

但是,可以将图像数据编码为 base64 并将其直接放置在应用程序的 HTML 正文中。我不会在此处包含代码(您可以轻松地通过谷歌搜索),因为这很棘手且有问题,因为并非所有读者都会正确解释这一点。

如果这是所有电子邮件都相同的标题图像,您可以将其放在服务器上的某个位置,然后在引用该文件的 HTML 电子邮件正文中包含 标记。

如果这是动态图像,您可以让您的应用将其上传到众多图像托管站点之一,检索 URL 并再次将其包含为 src 。 HTML 电子邮件正文中的 code> 标记。

When you attach an image using the MFMailComposeViewController it is always displayed at the bottom of the message (under your text, but above the signature) and this cannot be changed in the current version of the framework.

It is possible, however, to encode your image data into base64 and place this directly in the HTML body of your app. I won't include the code here (you can easily google it) because this is tricky and problematic since not all readers will interpret this correctly.

If this is a header image that will be the same for all emails you can put this on a server somewhere and then include an <img> tag in your HTML email body that references this file.

If this is a dynamic image you can have your app upload it to one of the many image hosting sites, retrieve the url and again include it as the src of an <img> tag in your HTML email body.

哆兒滾 2024-10-28 06:02:02

您应该使用 MFMailComposeViewController 类中的 - (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename 方法。

这是 这方面的一个很好的例子,它展示了从相机中拍摄图像,然后向其发送电子邮件!

You should use the - (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename method from the MFMailComposeViewController class.

Here's a great example of this that shows taking an image from the camera and then sending it an an email message!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文