Search code examples
objective-cxcodeiphone-4

See if CGDataProviderRef returns an error?


I am getting a pdf document the following way :

myPDFData = (CFDataRef)PDFDataContent;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);

pdfDocument = CGPDFDocumentCreateWithProvider(provider);

PDFDataContent is the returned data from a URLRequest.

But some times I get an error

 failed to find PDF header: `%PDF' not found.

I am not bothered about the error itself, I know why this happens. What I want is to know when I do get this so I can let the user know that an error has happened. So how can I access this message to print it out into lets say a UIAlertView?


Solution

  • It was a very simple answer don't know why I didn't think of it before.

    if(pdfDocument != NULL) {
        NSLog(@"Document downloaded");
    } else {
        NSLog(@"Error : Document not downloaded");
    }