我需要我的应用识别.PDF
扩展程序,然后在Safari而不是UIWebView
中打开它,但如果我调用http://google.com之类的域名,我希望它能够打开它在UIWebView
。
请建议
答案 0 :(得分:1)
您也可以检查MIME类型,以获得稍长的旅程:
@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"]);
}
您应该使用以下打开URL文件(.pdf):
NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com/dd.pdf"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(@"%@%@",@"Failed to open url:",[url description]);
答案 1 :(得分:0)
试试这个它将在safari中打开,而不使用webview
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil && [url isFileURL]) {
if ([[url pathExtension] isEqualToString:@"pdf"]) {
NSLog(@"URL:%@", [url absoluteString]);
}
}
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"your pdf url"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(@"%@%@",@" open url:",[url description]);
}