2015-02-05 7 views
-1

다음은 내 애플리케이션에 사용하는 것입니다. 이것은 iOS 7에서는 정상적으로 작동하지만 iOS 8에서는 충돌이 발생합니다.PDF를 생성하는 동안 UIGraphicsEndPDFContext를 호출 할 때 iOS 8에서 충돌이 발생합니다.

이 방법을 사용하여 스크린 샷을 찍은 다음 pdf를 작성하여 이메일로 전송합니다.

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename 
{ 
    // Creates a mutable data object for updating with binary data, like a byte array 
    NSMutableData *pdfData = [NSMutableData data]; 

    // Points the pdf converter to the mutable data object and to the UIView to be converted 
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); 
    UIGraphicsBeginPDFPage(); 
    CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 

    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 
    [aView.layer renderInContext:pdfContext]; 

    // remove PDF rendering context 
    UIGraphicsEndPDFContext(); 


    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:30.0/255.0 green:172.0/255.0 blue:254.0/255.0 alpha:1]]; 


    if ([MFMailComposeViewController canSendMail]) 
    { 
     MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 
     mailer.mailComposeDelegate = self; 
     [mailer setSubject:@"Payment Receipt"]; 

     [mailer addAttachmentData:pdfData mimeType:@"application/pdf" fileName:[NSString stringWithFormat:@"%@",aFilename]]; 
     NSString *emailBody = @"Payment Receipt"; 
     [mailer setMessageBody:emailBody isHTML:NO]; 
     [[mailer navigationBar] setTintColor:[UIColor whiteColor]]; 


     [self presentViewController:mailer animated:YES completion:nil]; 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email error!" 
                 message:@" You do not have an email address configured in your device" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 

    } 


} 

나는 그것이 UIGraphicsEndPDFContext()

에서 정지 볼 수있는 예외 중단 점을 추가

없이 성공 솔루션을 지난 3 일 찾기 위해 노력하고있다.

+0

가 관련된 이메일 opition 만들기 오류? – usr2564301

+0

그들은 오류의 일부가 아닙니다. 그러나 완전한 가시성을 제공하므로 전체 코드를 배치해도 아무런 해가 없습니다. –

답변

1

여기가 내가 사용했던 것이며 작동합니다. 코드에서 다른 자리에 그런

-(NSData *) createPDFDataFrom:(UIView *) aView 
{ 
    // Creates a mutable data object for updating with binary data, like a byte array 
    NSMutableData *pdfData = [NSMutableData data]; 

    // Points the pdf converter to the mutable data object and to the UIView to be converted 
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); 
    UIGraphicsBeginPDFPage(); 
    CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 

    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 

    [aView.layer renderInContext:pdfContext]; 

    // remove PDF rendering context 
    UIGraphicsEndPDFContext(); 
    return pdfData; 
} 

:

// 당신은 당신의 코드 (그리고 질문)의 '메일을 보내'부분이 되었습니까

 MFMailComposeViewController * mailVC = [[MFMailComposeViewController alloc] init]; 
     mailVC.mailComposeDelegate = self; 

     [mailVC setSubject:[NSString stringWithFormat:@"%@: %@",@"Report",self.graphicContainer.graphicContainerName]]; 

     [mailVC addAttachmentData:[self createPDFDataFrom:self.baseView] mimeType:@"pdf" fileName:[NSString stringWithFormat:@"%@.pdf",@"Report"]]; 
     [self presentViewController:mailVC animated:YES completion:nil]; 
     [mailVC release]; 
+0

이것은 나에게도 효과가 없었습니다. 문제를 파악할 수 없습니다. 나는 iOS 8을위한 체크 포인트를 놓았고 그것들을 위해 jpeg 이미지를 첨부 파일로 보낼 것입니다. –