iPhone - 无论如何在自己的应用程序中获取iPhone的电子邮件应用程序?

bbu*_*s21 2 email iphone

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

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

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

Gar*_*ett 5

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

#import <MessageUI/MessageUI.h>
@interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
    MFMailComposeViewController *email;
}

@property (nonatomic, retain) MFMailComposeViewController *email;
Run Code Online (Sandbox Code Playgroud)

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

@synthesize email;

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [email dismissModalViewControllerAnimated:YES];
} 
Run Code Online (Sandbox Code Playgroud)

无论你想在哪里使用它,你需要初始化并设置如下:

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];
Run Code Online (Sandbox Code Playgroud)