Check if UIWebview PDF is displaying

To be clear, my question is: do not ask how to display PDF in UIWebview. I want to check if the user has moved to a PDF document (.pdf) from any website or link. This way, I can show more possibilities for the user, for example, save a PDF or print it. What is the best way to check if UIWebView PDF content is?

+4
source share
2 answers

You can also check the MIME type for a longer trip:

@property (nonatomic, strong) NSString *mime; - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { mime = [response MIMEType]; } - (BOOL)isDisplayingPDF { NSString *extension = [[mime substringFromIndex:([mime length] - 3)] lowercaseString]; return ([[[self.webView.request.URL pathExtension] lowercaseString] isEqualToString:@"pdf"] || [extension isEqualToString:@"pdf"]); } 
+5
source

It's a long trip, but I think it will work ...

 BOOL isPdf = [[[self.webView.request.URL pathExtension] lowercaseString] isEqualToString:@"pdf"]; 
0
source

All Articles