本文介绍了UIWebview禁用重定向到AppStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有 UIWebview
,这就是我在应用程序中导航到 URL
的方式:
I have UIWebview
in my app and this is how i navigate some times in the application to URL
:
NSURL *url = [NSURL URLWithString:@"http://mp3skull.com/mp3/nirvana.html"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
有时我会注意到,如果我单击链接,则会使用某些应用程序打开 AppStore
应用程序.
And sometimes i noticed that if i click on link the AppStore
application is opened with some app.
可以禁用它吗?
推荐答案
在方法-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)请求导航类型:(UIWebViewNavigationType)navigationType
您可以
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *requestedURL = [[request URL] absoluteString];
// URL for opening itunes according to Apple docs is something like this @"http://itunes.apple.com
// But I do believe that it will be some sort of URL scheme that opens it specifically to the app on the app store.
// So without an example this is the best I can provide.
if([requestedURL isEqualToString:@"http://itunes.apple.com"]) {
// or if([requestedURL rangeOfString:@"itunes.apple.com"].location==0) {
// What is happening here is that if the request url that is being request is
// "http://mp3skull.com/mp3/nirvana.html" then we don't want to continue with the request so stop.
return NO;
}
// Otherwise for all other requests continue
return YES;
}
记住,您将需要在 UIWebView
上设置委托,因为此方法是 UIWebViewDelegate
方法-请参见在 UIWebViewDelegate
上的Apple文档>了解更多信息
Remember you will need to set the delegate on your UIWebView
as this method is a UIWebViewDelegate
method - see Apple Documentation on UIWebViewDelegate
for more information
这篇关于UIWebview禁用重定向到AppStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!