I get this log when i try to load a pdf and don't know why.
failed to find PDF header: `%PDF' not found.
hers my code:
- (void)viewDidLoad
{
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://webdesign-schoenefeld.de/es-app/heute.pdf"]]];
NSLog(@"---------------pdfloading....,------------------------");
[webview addSubview:activityind];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0)
target:self
selector:@selector(loading)
userInfo:nil
repeats:YES];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
I use Xcode 6 Beta 5 and iOS 8 beta 5.
Thanks for your help.
I agree, there seems to be a bug (or change of behaviour) in iOS 8 beta 5 which means that your code does not work anymore (and it was valid. I have the same and it worked fine up to iOS 8 beta 4).
I think there is a problem with type detection because if I do the following, it works:
NSLog(@"About to request PDF document loading...");
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlStr]];
[self.webView loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
Now that bit of code should not be used "as is" as it is synchronous.
I feel Nithin's answer was valid but it does not answer the problem specifically seen with iOS 8 beta 5. The main code is the same and will hit the same iOS bug.
This worked for me 👊👍
NSURL *targetURL = [NSURL fileURLWithPath:pdfFilePath]; // <pdfFilePath> if full path of your pdf file
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:targetURL];
[self.webview loadData:pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With