2009-11-22 7 views
0

Je veux que mon application envoie un message. Je peux utiliser le schéma mailto: URL, mais il met fin à mon application lors du lancement du courrier iPhone. Le lecteur de nouvelles de The Independent (papier britannique) semble faire apparaître une vue de composition de courrier au sein de l'application. Lorsque vous envoyez ou annulez, l'application réapparaît immédiatement.embed mail compose dans une application iPhone

Est-ce que quelqu'un sait comment faire cela?

grâce,

Répondre

3

Vous devez utiliser 3.0 Message Framework UI!

0
#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 
} 
Questions connexes