【问题标题】:iPhone - Anyway to get iPhone's Email App Inside Your Own App?iPhone - 无论如何要在您自己的应用程序中获取 iPhone 的电子邮件应用程序?
【发布时间】:2009-09-03 23:36:24
【问题描述】:

有没有人将 iPhone 的电子邮件程序嵌入到自己的应用程序中?

让我试着简化一下。 Tap Tap Revenge 允许您“挑战朋友”。当您选择这样做时,他们会在应用程序中打开标准的 iPhone 电子邮件程序(如果他们模仿它,它看起来非常好),其中包含预先填充的数据。您所要做的就是从您的联系人中选择一个朋友,然后按发送。您永远不会离开 Tap Tap Revenge 应用程序。

任何想法如何做到这一点?

【问题讨论】:

    标签: iphone email


    【解决方案1】:

    您需要将MessageUI.framework 包含到您的项目中,并在您的头文件中设置委托:

    #import <MessageUI/MessageUI.h>
    @interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
        MFMailComposeViewController *email;
    }
    
    @property (nonatomic, retain) MFMailComposeViewController *email;
    

    完成此操作后,您需要在实现文件中包含一些委托方法(您应该检查以查看结果,但我试图根据需要保留尽可能少的代码):

    @synthesize email;
    
    - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
        [email dismissModalViewControllerAnimated:YES];
    } 
    

    无论你想在哪里使用它,你都需要像这样初始化和设置它:

    email = [[MFMailComposeViewController alloc] init];
    email.mailComposeDelegate = self;
    
    // Subject
    [email setSubject:@"Testing"];
    
    // Optional Attachments
    NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:@"albumart.png"]);
    [email addAttachmentData:artwork mimeType:@"image/png" fileName:@"albumart.png"];
    
    // Body
    [email setMessageBody:@"This is the body"];
    
    // Present it
    [self presentModalViewController:email animated:YES];
    

    【讨论】:

    • 谢谢,这将为我指明正确的方向并让我开始!非常感谢。
    【解决方案2】:

    除了 Garett 的出色回应,如果您收到警告:

    'MFMailComposeViewController' 可能不会响应'-setMessageBody:'

    添加 isHTML: 所以整行如下:

    [mail setMessageBody:@"这是正文" isHTML:NO];

    【讨论】:

      【解决方案3】:

      对此有两个答案。对于应该支持 3.0 之前的 iPhone OS 的应用程序,唯一的方法是构建自定义消息编辑器。或者您可能想看看由编写 Facebook iPhone 应用程序的 Joe Hewitt 构建的组件。

      http://github.com/joehewitt/three20/blob/master/src/Three20/TTMessageController.h

      使用 iPhone SDK 3.0,如果使用上述 MessageUI.framework 的框,您可以直接使用邮件消息编辑器 UI。

      【讨论】:

        【解决方案4】:

        messagecomposer 是要走的路!应用程序内的邮件和短信,从 iOS 3.1 运行。需要sdk 4

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-05-17
          • 2010-12-02
          • 1970-01-01
          • 2012-01-27
          • 1970-01-01
          • 1970-01-01
          • 2011-05-08
          相关资源
          最近更新 更多