2012-10-27 4 views
0

텍스트 필드와 이미지의 데이터가 포함 된 이메일을 보내려하는데 작동하지 않는 경우 알려주세요. 여기 내 코드는 다음과 같습니다.앱에서 이메일을 보내는 방법

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
if(buttonIndex==1) 
{ 

    Cocktails*c=[[Cocktails alloc]init]; 

    _arrTextField=[NSArray arrayWithObjects:_txtName,_txtIngredients,_txtPreper,_txtServe,_txtFrom ,nil]; 

    NSLog(@"send email"); 

    if ([MFMailComposeViewController canSendMail]) 
    { 
    NSMutableArray*recipients=[[NSMutableArray alloc]init]; 

    [recipients addObject:@"[email protected]"]; 
    MFMailComposeViewController *controller= [[MFMailComposeViewController alloc]init]; 
    controller.mailComposeDelegate= self; 
    [controller addAttachmentData:_imgDrink mimeType:@"image/png" fileName:@"Myimage"]; 
    [controller setSubject:@"my cocktail"]; 
    [controller setMessageBody: _arrTextField isHTML:NO]; 
    [controller setToRecipients:recipients]; 
    } 
    else 
    { 
     UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Your devise is not set up for Email" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil, nil]; 

     [alert show]; 
     // [alert release]; 
    } 

답변

0

메일 컨트롤러를 절대로 제시하지 마십시오. 다른 모달 뷰 컨트롤러와 마찬가지로 표시해야합니다. 도움이 여기에

0

:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the drafts folder."); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); 
      break; 
     default: 
      NSLog(@"Mail not sent."); 
      break; 
    } 

    // Remove the mail view 
    [self dismissModalViewControllerAnimated:YES]; 
} 


-(IBAction)sendCode:(id)sender { 
    if ([MFMailComposeViewController canSendMail]) 
    { 
     MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 

     mailer.mailComposeDelegate = self; 

     [mailer setSubject:@"Your subject"]; 

     NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil]; 
     [mailer setToRecipients:toRecipients]; 

UIImage *myImage = [UIImage imageNamed:@"MyImage.png"]; 
      NSData *imageData = UIImagePNGRepresentation(myImage); 
      [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"myimag 

e"]; 


     NSString *emailBody = 
     @"your body"; 


     [mailer setMessageBody:emailBody isHTML:NO]; 


     [mailer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
     [self presentModalViewController:mailer animated:YES]; 

    } 
    else { 
     { 
      UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Error" 
                  message:@"Your device doesnt support that action." 
                  delegate:nil 
                cancelButtonTitle:@"Okay" 
                otherButtonTitles:nil]; 

      [alert2 show]; 



     } 
    } 
} 

과 .H 파일 추가에

:

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 

@interface Controller : UIViewController <MFMailComposeViewControllerDelegate> { 


} 

-(IBAction)send:(id)sender; 

@end 
+0

귀하의 솔루션이어야합니다! – MasterRazer

+0

감사합니다,하지만 이메일 화면을보고 싶지 않습니다. 자동으로 보내고 싶습니다. – user1763326

+0

오, 오케이 내 잘못을 찾아 보겠습니다. – MasterRazer

0

당신은보기 자동 전송 사과는 늘 당신이 사용자의 지식없이 사물의 종류의 일을 할 수 있기 때문에 이메일 캔트. presentModalView를 제시해야합니다!

관련 문제