0

카메라 첨부 이미지를 전자 메일에 첨부하는 방법을 테스트하는 샘플 응용 프로그램을 만들었습니다. 그 안에는 2 버튼이 있습니다. MFMailComposeViewControlleriOS- 카메라 픽업 이미지를 전자 메일에 첨부하여 이상한 동작

imageAttachment을 열고 카메라 & 다른 버튼 (이메일 버튼)를 엽니 한 (카메라 버튼)은 위에있는 UIImage 유형

#pragma mark - Picker Controller delegate 
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    imageAttachment = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

// [self performSelector:@selector(dismissCamera) withObject:nil afterDelay:2.0]; 

    [self performSelector:@selector(emailImage) withObject:nil afterDelay:1.0]; 
    [self dismissModalViewControllerAnimated:YES]; 

    [picker release]; 
} 

로 .H 파일에 선언 방법 나는 문제에 직면했다. 내가

[self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0]; 
[self dismissModalViewControllerAnimated:YES]; 

이후

// [self performSelector:@selector(dismissCamera) withObject:nil afterDelay:2.0]; 

& 주석에게 선을 아래 라인의 주석을 해제하면 나는 다음이 충돌합니다 이메일 버튼을 누릅니다. 이상한 점은 왜 충돌하는 것입니까? 오류없이 충돌합니다.?

이들은 다른 방법

- (void)emailImage 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    [picker setToRecipients:toRecipients]; 

    [picker setSubject:@"Photo"]; 

    NSString *emailBody = @"Photo clicked ; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    // Create NSData object as PNG image data from camera image 
    NSData *myData = UIImagePNGRepresentation(imageAttachment); 

    // Attach image data to the email 
    // 'CameraImage.png' is the file name that will be attached to the email 
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"CameraImage.png"]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 

아래 앱 충돌 코드입니다.

- (void)dismissCamera 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (IBAction)btnEmailTouched:(id)sender 
{  
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
    if (mailClass != nil) 
    { 
     // We must always check whether the current device is configured for sending emails 
     if ([mailClass canSendMail]) 
      [self displayComposerSheet]; 
     else 
      [self launchMailAppOnDevice]; 
    } 
    else 
     [self launchMailAppOnDevice]; 
} 

#pragma mark Compose Mail 
// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayComposerSheet 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Photo"]; 

    [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]]; 

    NSString *emailBody = @"Photo clicked; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    // Create NSData object as PNG image data from camera image 
    NSData *data = UIImagePNGRepresentation(imageAttachment); 

    // Attach image data to the email 
    // 'CameraImage.png' is the file name that will be attached to the email 
    [picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage.png"]; 

    [self presentModalViewController:picker animated:YES]; 

    [picker release]; 
} 

PS : 두 방법, - (void)emailImage & -(void)displayComposerSheet 라인과 동일한 부호를 사용한다. 나는 이메일 첨부 파일과 같은 imageAttachemnt 객체를 부착하고,하지만 난 카메라 & 이메일 버튼가 왜이 방법 피커를 해제하는 MFMailComposeViewController

+0

당신이 완전히 을 사용자 정의 예를 아래에서 확인하실 수 있습니다 https://github.com/zhanleewo/ZLMailComposerViewController 카메라 버튼도 사진을 첨부 훨씬 더 또한 첨부 파일 목록 availabl 할 수있다 e –

답변

0

를 열려면 터치를 해제 할 때 그것은 실패

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
+0

피커 인스턴스를 해제하지 않고 동일한 코드를 실행했습니다. 성공하지 못했습니다 : ( –

+0

잘못된 액세스 또는 sigbart가 있습니까? – Talha

+0

그냥 오류없이 중단됩니다. 중단 점을 넣으면 이미지가 데이터로 변환되지 않습니다. –