gpt4 book ai didi

iphone - 从应用程序和电子邮件中检索保存的图像

转载 作者:行者123 更新时间:2023-12-03 19:45:07 24 4
gpt4 key购买 nike

用户拍照后,我成功将图像保存到我的应用程序中。我稍后想做的是,当用户返回应用程序时,我希望他们能够将照片作为附件通过电子邮件发送。我没有运气将应用程序中的数据转换为图像,因此我可以添加为附件。有人可以指出我正确的方向吗?这是我在拍摄照片后保存图像的地方。

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{


//here is the image returned

app.aImage2 = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation( app.aImage2 );
NSString * savedImageName = [NSString stringWithFormat:@"r%@aImage2.png",app.reportNumber];
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * dataFilePath;
dataFilePath = [documentsDirectory stringByAppendingPathComponent:savedImageName];
[imageData writeToFile:dataFilePath atomically:YES];



[self dismissModalViewControllerAnimated:YES];


}

这是我需要附加它的地方。

//this is inside my method that creates an email composer view
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet

//how would i attach the saved image from above?

最佳答案

这包括迈克在这里提到的代码:

How to add a UIImage in MailComposer Sheet of MFMailComposeViewController

此外,其他部分摘自 Sagar Kothari 的回答:

Sending out HTML email with IMG tag from an iPhone App using MFMailComposeViewController class

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Dismiss image picker modal.
[picker dismissModalViewControllerAnimated:YES];

if ([MFMailComposeViewController canSendMail]) {
// Create a string with HTML formatting for the email body.
NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"];

// Add some text to it.
[emailBody appendString:@"<p>Body text goes here.</p>"];

// You could repeat here with more text or images, otherwise
// close the HTML formatting.
[emailBody appendString:@"</body></html>"];
NSLog(@"%@", emailBody);

// Create the mail composer window.
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;

// Image to insert.
UIImage *emailImage = [info objectForKey:UIImagePickerControllerOriginalImage];

if (emailImage != nil) {
NSData *data = UIImagePNGRepresentation(emailImage);
[emailDialog addAttachmentData:data mimeType:@"image/png" fileName:@"filename_goes_here.png"];
}

[emailDialog setSubject:@"Subject goes here."];
[emailDialog setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];
}
}

关于iphone - 从应用程序和电子邮件中检索保存的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6025217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com