2017-02-17 42 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教程中找到更多的信息

相關問題