如何使用 MFMailComposeViewController 发送图像

发布于 2025-01-06 05:37:53 字数 1541 浏览 0 评论 0原文

我正在尝试使用 MFMailComposeViewController 发送电子邮件,但不知何故它不起作用。当我不发送图像时,一切正常。但如果我尝试添加照片,则会出现以下错误:

-(IBAction)gonder:(id)sender{
  MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
  mailComposeViewController.mailComposeDelegate = self;

  [mailComposeViewController setSubject:@"deneme"];
  UIImage *savedImage = self.image;
  NSData *imageData = UIImagePNGRepresentation(savedImage);
  [mailComposeViewController addAttachmentData:imageData mimeType:@"image/png" fileName:@"photo"];
  NSString *emailBody = @"my text";
  [mailComposeViewController setMessageBody:emailBody isHTML:NO];

  [emailBody release];
  NSArray *alicilar=[[NSArray alloc]initWithObjects:@"mymailadress.com", nil];
  [mailComposeViewController setToRecipients:alicilar];

  [mailComposeViewController view];
}

- (void) mailComposeController:(MFMailComposeViewController*)mailComposeViewController bodyFinishedLoadingWithResult:(NSInteger)result error:(NSError*)error
{
  @try
  {
    id mailComposeController = [mailComposeViewController valueForKeyPath:@"internal.mailComposeController"];
    id sendButtonItem = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.sendButtonItem"];
    [mailComposeController performSelector:@selector(send:) withObject:sendButtonItem];
  }
  @catch (NSException *e) {}
  [mailComposeViewController release];
}

这些是错误:
2012-02-14 16:19:58.322 il[653:307] *** 错误:FigCreateCGImageFromJPEG 返回 -12905。输入(空)为 444585 字节。

I am trying to send an email using MFMailComposeViewController but somehow it won't work. When I don't send an image everything works just fine. But if I try to add photo there is the following error:

-(IBAction)gonder:(id)sender{
  MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
  mailComposeViewController.mailComposeDelegate = self;

  [mailComposeViewController setSubject:@"deneme"];
  UIImage *savedImage = self.image;
  NSData *imageData = UIImagePNGRepresentation(savedImage);
  [mailComposeViewController addAttachmentData:imageData mimeType:@"image/png" fileName:@"photo"];
  NSString *emailBody = @"my text";
  [mailComposeViewController setMessageBody:emailBody isHTML:NO];

  [emailBody release];
  NSArray *alicilar=[[NSArray alloc]initWithObjects:@"mymailadress.com", nil];
  [mailComposeViewController setToRecipients:alicilar];

  [mailComposeViewController view];
}

- (void) mailComposeController:(MFMailComposeViewController*)mailComposeViewController bodyFinishedLoadingWithResult:(NSInteger)result error:(NSError*)error
{
  @try
  {
    id mailComposeController = [mailComposeViewController valueForKeyPath:@"internal.mailComposeController"];
    id sendButtonItem = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.sendButtonItem"];
    [mailComposeController performSelector:@selector(send:) withObject:sendButtonItem];
  }
  @catch (NSException *e) {}
  [mailComposeViewController release];
}

Those are the errors:
2012-02-14 16:19:58.322 il[653:307] *** ERROR: FigCreateCGImageFromJPEG returned -12905. Input (null) was 444585 bytes.

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

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

发布评论

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

评论(2

望喜 2025-01-13 05:37:53

您尝试附加的图像非常大吗?这可能是内存不足的问题。

Is the image you are trying to attach very large? It may be an out of memory problem.

情话墙 2025-01-13 05:37:53

我认为问题在于创建数据对象的方式。试试这个:

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(savedImage)];

也可以考虑使用 JPEG 而不是 PNG,它的速度要快得多。

i think the issue is the way you create the data object. try this:

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(savedImage)];

also consider maybe using JPEG instead of PNG, it's quite a bit faster.

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