【问题标题】:Attachments using email uri scheme in iOS在 iOS 中使用电子邮件 uri 方案的附件
【发布时间】:2012-01-12 10:58:01
【问题描述】:

我正在实现一个 iphone 应用程序 (iOS 4.2),我想从该应用程序触发电子邮件客户端发送带有附件的消息。我可以有效地结合使用 uri 方案和类 NSURL 来触发电子邮件应用程序,但我想知道是否可以附加图像。我尝试使用 mailto:whoever@wherever.org?subject=sthg&body=sthgelse&attachment=/path/to/file 但附件不包括在内。我知道 iphone 应用程序是沙盒的,因此电子邮件实用程序可能无法访问我的图像路径,因为它位于我的应用程序包中。另一方面,我正在考虑使用照片管理器管理我的图像。 (1)有没有办法以这种方式包含附件? (2) 如果是这样,是否可以从我的应用程序或照片客户端引用图像?我在 mailto RFC 中找不到任何附件参数,但也许 Apple 提供了一些方法来实现这一点。

提前感谢您的帮助,

路易斯

【问题讨论】:

    标签: iphone ios email ios4 url-scheme


    【解决方案1】:

    MFMailComposeViewController 将能够做到这一点,下面的一些使用示例: 记得添加 MessageUI.framework

    MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
    email.mailComposeDelegate = self;
    [email setSubject:@"Whatever"];
    
    // Set up recipients
    NSArray recipients = [NSArray arrayWithObject:@"whoever@wherever.org"]; 
    
    [email setToRecipients:recipients];
    
    
    // Attach an image to the email
    UIImage *attachment = ...;
    NSData *data = UIImagePNGRepresentation(attachment);
    [email addAttachmentData:myData mimeType:@"image/png" fileName:@"ok.png"];
    
    // Fill out the email body text
    NSString *emailBody = @"test mail";
    [email setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:picker animated:YES];
    
    [email release];
    

    【讨论】:

    【解决方案2】:

    您应该使用MFMailComposeViewController,而不是使用mailto: URL 方案,它允许您添加附件。它还具有额外的好处,即使用不会离开您的应用程序。

    【讨论】:

    • 谢谢.. 这似乎是正确的做法。毕竟mailto方案没有考虑任何参数来表达附件..
    【解决方案3】:

    如果没有帐户 MFMailComposeViewController 只会崩溃。 是的,您可以先致电canSendMail,结果为 NO(!),接下来呢? 答案是 - 使用'mailto:'。它会弹出对话框来创建帐户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      相关资源
      最近更新 更多