0
打開window.open方法我是新來的iOS開發如何在IOS Objective C的Safari瀏覽器使用的WebView
我開發一個應用程序在UIWebView
打開網址,但該網站工作正常,在safari
網頁瀏覽器,但當我錄製鏈接編碼爲window.open()
時,它將加載相同的webview
。這裏是我的代碼
ViewController.h文件
//
// ViewController.m
//
//
// Created by Code Kadiya on 5/18/17.
// Copyright © 2017 Code Kadiya. All rights reserved.
//
#import "ViewController.h"
@interface ViewController() <UIWebViewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.webView setDelegate:self];
// Do any additional setup after loading the view, typically from a nib.
NSURL *websiteUrl = [NSURL URLWithString:@"http://some.url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:websiteUrl cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:15.0];
[_webView loadRequest:request];
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *url = [request URL];
[[UIApplication sharedApplication] openURL: url options:@{} completionHandler:nil];
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
,我發現加載Web應用程序的源代碼,這
<a onclick="open_pdf('office')" target="_blank">
function open_pdf(type) {
window.open("http://some.url?type=" + type);
}
無論如何我需要打開Safari瀏覽器,當我點擊該鏈接,但我無法更改網絡應用源代碼
我認爲
[[UIApplication sharedApplication] openURL: url options:@{} completionHandler:nil];
該類型的鏈接
希望這有助於:https://stackoverflow.com/a/2899793/775896 – Mrunal
@code卡地亞添加一個破發點中'如果(navigationType == UIWebViewNavigationTypeLinkClicked){}'條件,看它是否被執行或不 – Maddy
@Maddy Nope buddy它不執行,因爲有'UIWebViewNavigationTypeOther'類型,但我無法通過'UIWebViewNavigationTypeLinkClicked'處理'window.open()' –