Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在创建pdf时调用UIGraphicsSendPdfContext时在iOS 8中崩溃_Ios_Iphone_Pdf_Ios8 - Fatal编程技术网

在创建pdf时调用UIGraphicsSendPdfContext时在iOS 8中崩溃

在创建pdf时调用UIGraphicsSendPdfContext时在iOS 8中崩溃,ios,iphone,pdf,ios8,Ios,Iphone,Pdf,Ios8,下面是我在应用程序中使用的内容。这在iOS 7中运行良好,但在iOS 8中崩溃 使用这种方法,我截图并创建pdf,然后通过电子邮件发送 -(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename { // Creates a mutable data object for updating with binary data, like a byte array

下面是我在应用程序中使用的内容。这在iOS 7中运行良好,但在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()


在过去的三天里,我们一直试图找到解决方案,但没有成功

这是我用过的,而且很有效

-(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];

您是否发现代码(和问题)中的“发送邮件”部分与错误相关?它们不是错误的一部分。但是放置完整的代码并没有坏处,因为它提供了完整的可视性。这对我来说也不起作用。无法解决问题。我为iOS 8设置了一个检查点,并将jpeg图像作为附件发送给他们。