2014-07-24 3 views
0

나는 화면을 캡처하고 몸 이 내 코드에서, 이메일로 바람직 해당 이미지를 보내려고하지만 :(캡처 스크린 샷 및 이메일 본문에 보내기

- (IBAction) Btn_Clicked: (id) sender 
{ 
    //take the screenshot 
    UIGraphicsBeginImageContext(self.view.bounds.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    NSData* imageData = UIImageJPEGRepresentation(screenshotImage, 1); 

    //prepare the email form 
    NSString *emailTitle = MESSAGE_EMAIL_TTITLE; 
    NSString *messageBody = MESSAGE_EMAIL_TEXT; 

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
    mc.mailComposeDelegate = self; 
    [mc setSubject:emailTitle]; 
    [mc setMessageBody:messageBody isHTML:NO]; 

    // Add attachment 
    [mc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:nil]; 

    // Present mail view controller on screen 
    [self presentViewController:mc animated:YES completion:NULL]; 

} 


- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail sent"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
      break; 
     default: 
      break; 
    } 

    // Close the Mail Interface 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
} 

답변

1

을 작동하지 않습니다

[mc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"screenshot.jpg"]; 

[mc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:nil]; 

교체

관련 문제