gpt4 book ai didi

ios - UIWebView 在 Safari 中启动

转载 作者:行者123 更新时间:2023-11-29 13:04:58 24 4
gpt4 key购买 nike

我知道这个问题已经被提出很多次并且在这个网站上回答了两倍,但是我想我可能有一些不同的东西并且需要知道它是否可能。

我正在尝试将横幅广告从网站加载到应用程序的 UIWebView 中。所有这一切都完美无缺。但是,无论我尝试实现什么代码,我都无法获取它,因此当在应用程序中点击广告时,它会在 safari 中启动。

基本上我想拥有自己的广告服务器。该广告是托管在我们网站上的托管广告。横幅中包含服务器嵌入的链接。

这是我正在使用的代码。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSString *string;
string = @"http://www.samplesite.com/mobile_ads";
NSURL *url = [NSURL URLWithString: string];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.adBox loadRequest:requestObj];
}

-(BOOL) adBox:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}

return YES;
}

我应该去哪里有什么想法吗?

最佳答案

在你的UIWebViewDelegatewebView:shouldStartLoadWithRequest:navigationType:方法,执行类似以下操作(假设您的广告有部分网址可识别):

- (void)methodThatCreatesTheWebview {
UIWebView *webview = [[UIWebView alloc] init];
webview.delegate = self;
}


// Portion of the URL that is only present on ads and not other URLs.
static NSString * const kAd = @"adSubdominOrSubDirectory";

// pragma mark - UIWebViewDelegate Methods

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.absoluteString rangeOfString:kAd] != NSNotFound) {
// Launch Safari to open ads
return [[UIApplication sharedApplication] openURL:request.URL];
} else {
// URL isn't an ad, so just load it in the webview.
return YES;
}
}

关于ios - UIWebView 在 Safari 中启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18880620/

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