繁体   English   中英

如何通过我的网络视图应用打开safari中的.pdf文件

[英]how to open .pdf files in safari from my web view app

我的网络应用程序停留在一个网络视图中,并在Safari中打开域外的链接。 我需要做的是添加域中的.pdf文件以在Safari中打开。 截至目前,它们已在网络视图中打开,并且没有导航可退出,因此您必须强制使用该应用并重新启动。

    - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://rbc.samkingmedia.com"]]];
    _webView.delegate = self;
    [_webView addSubview:activityind];
    timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];

}

-(void)loading {
    if (!_webView.loading)
        [activityind stopAnimating];
    else
        [activityind startAnimating];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {


    //  open External Links (not beginning with www.playbuzz.org/ in Safari.app
    if (
        (navigationType == UIWebViewNavigationTypeLinkClicked) &&
        ( ![[[request URL] absoluteString] hasPrefix:@"http://rbc.samkingmedia.com/"])
        ) {

        [[UIApplication sharedApplication] openURL:request.URL];
        return NO;
    }

    //open Internal links in uiwebview
    return YES;
}

如果要添加导航,则应使用SFSafariViewController

它是一个快速代码示例

let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!, entersReaderIfAvailable: true)
self.presentViewController(svc, animated: true, completion: nil)

您可以在教程中找到更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM