2017-02-17 54 views
0

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

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

回答

0

,如果你想添加导航,你应该使用SFSafariViewController

其SWIFT代码的例子

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

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

相关问题