UIWebView在Safari中启动

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

我试图从网站加载一个横幅广告到应用程序中的UIWebView。 所有这些工作完美无瑕。 然而,无论我试图实现什么代码,我都无法得到它,所以当在应用程序中点击广告时,它将在Safari中启动。

基本上我想有我自己的广告服务器。 广告托pipe在我们的网站上。 横幅中有由服务器embedded的链接。

这是我正在使用的代码。

- (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:方法中,执行如下操作(假设您的广告的部分url可识别):

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