gpt4 book ai didi

ios - 在 Safari 中从 UIWebView 打开外部链接

转载 作者:行者123 更新时间:2023-11-29 01:40:36 28 4
gpt4 key购买 nike

我想修改我的代码,以便在 Safari 上打开外部链接,而不是我的应用程序的应用程序内浏览器。 html 文件是从内部路径加载的,所以我不知道如何让应用程序了解所有外部链接都必须在 safari 中打开。

这是我的 ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *fullURL = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_viewWeb loadRequest:requestObj];
}

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

@end

我该如何修改呢?谢谢!

最佳答案

您需要在 UIWebView 委托(delegate)方法中处理此问题并检查 UIWebViewNavigationType

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

if(navigationType == UIWebViewNavigationTypeLinkClicked){

[MAIN_APPLICATION_DELEGATE openURL:request.URL];
}
}

关于ios - 在 Safari 中从 UIWebView 打开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434768/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com