如何从我的Web View应用程序中打开Safari中的.pdf文件



我的Web应用程序保留在一个Web视图中,并在Safari的域外打开链接。我需要做的是在Safari中添加域中打开的.pdf文件。到目前为止,他们在Web视图中打开了,没有导航才能退出它,因此您必须强制使用该应用程序并重新启动。

    - (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

它是Swift Code

中的一个示例
let svc = SFSafariViewController(URL: NSURL(string: self.urlString)!, entersReaderIfAvailable: true)
self.presentViewController(svc, animated: true, completion: nil)

您可以在这个教程

最新更新