我的应用程序中有 UIWebview
,这就是我在应用程序中有时导航到 URL
的方式:
NSURL *url = [NSURL URLWithString:@"http://mp3skull.com/mp3/nirvana.html"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
有时我注意到,如果我点击链接,AppStore
应用程序会打开一些应用程序。
是否可以禁用它?
最佳答案
在方法 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(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
上设置委托(delegate),因为此方法是 UIWebViewDelegate
方法 - 参见 Apple Documentation on UIWebViewDelegate
for more information
关于ios - UIWebview 禁用重定向到 AppStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909886/