0
我希望我的應用程序發送郵件。我可以使用mailto:URL方案,但它會在啓動iPhone郵件時終止我的應用程序。 The Independent(英國報紙)的新聞閱讀器似乎在應用程序中顯示郵件撰寫視圖。當您發送或取消時,應用會立即重新出現。嵌入郵件撰寫在iPhone應用程序
有誰知道如何做到這一點?
謝謝,
我希望我的應用程序發送郵件。我可以使用mailto:URL方案,但它會在啓動iPhone郵件時終止我的應用程序。 The Independent(英國報紙)的新聞閱讀器似乎在應用程序中顯示郵件撰寫視圖。當您發送或取消時,應用會立即重新出現。嵌入郵件撰寫在iPhone應用程序
有誰知道如何做到這一點?
謝謝,
您需要使用3.0 Message UI Framework!
#import <MessageUI/MessageUI.h>
@interface ViewReminderViewController_iPhone : UIViewController
<MFMailComposeViewControllerDelegate>
{
UiButton *mailButton;
}
- (IBAction)EmailButton:(id)sender;
@end
@implementation ViewController
- (IBAction)EmailButton:(id)sender
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Your EMail Subject"];
//SET UP THE RECIPIENTS (or leave not set)
//NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
//[picker setToRecipients:toRecipients];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
//[picker setCcRecipients:ccRecipients];
//NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
//[picker setBccRecipients:bccRecipients];
//ATTACH FILE
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MediaFiles"];
path = [path stringByAppendingPathComponent:MyFileName];
NSLog(@"Attaching file: %@", path);
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist?
{
NSLog(@"File exists to attach");
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/octet-stream"
fileName:@"DesredFileName.mov"];
}
//CREATE EMAIL BODY TEXT
NSString *emailBody = @"Your Email Body";
[picker setMessageBody:emailBody isHTML:NO];
//PRESENT THE MAIL COMPOSITION INTERFACE
[self presentModalViewController:picker animated:YES];
[picker release];
}
Delegate To Clear Compose Email View Controller
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES]; //Clear the compose email view controller
}