代码改变世界

程序跳转到itunes商店

2013-08-23 10:38  三戒1993  阅读(136)  评论(0编辑  收藏  举报

找到应用程序,点击应用程序下面的小三角图标,再选择”复制链接“,就可以获取此应用的链接了。

比如:

itunes.apple.com/cn/app/bai-du-wen-kuhd/id483064532?mt=8

然后将 https:// 替换为 itms:// 或者 itms-apps://:

然后在程序中写如下代码:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.apple.com/cn/app/bai-du-wen-kuhd/id483064532?mt=8"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes.apple.com/cn/app/bai-du-wen-kuhd/id483064532?mt=8"]]	
注意:只能在真机上调试出效果,模拟器上无效果。
"Error Domain=WebKitErrorDomain Code=101 The URL can't be shown."
http://stackoverflow.com/questions/4299403/how-to-handle-app-urls-in-a-uiwebview

http://stackoverflow.com/questions/4299403/how-to-handle-app-urls-in-a-uiwebview
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
   
// Give iOS a chance to open it.
    NSURL
*url = [NSURL URLWithString:[error.userInfo objectForKey:@"NSErrorFailingURLStringKey"]];
   
if ([error.domain isEqual:@"WebKitErrorDomain"]
       
&& error.code == 101
       
&& [[UIApplication sharedApplication]canOpenURL:url])
   
{
       
[[UIApplication sharedApplication]openURL:url];
       
return;
   
}

   
// Normal error handling…
}

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

    // Determine if we want the system to handle it.
    NSURL *url = request.URL;
    if (![url.scheme isEqual:@"http"] && ![url.scheme isEqual:@"https"]) {
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication]openURL:url];
            return NO;
        }
    }
    return YES;
}

- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
    // Ignore NSURLErrorDomain error -999.
    if (error.code == NSURLErrorCancelled) return;

    // Ignore "Fame Load Interrupted" errors. Seen after app store links.
    if (error.code == 102 && [error.domain isEqual:@"WebKitErrorDomain"]) return;

    // Normal error handling…
}

iphone开发笔记和技巧总结(原址持续更新)转载


http://www.cnblogs.com/zhwl/archive/2012/03/09/2387530.html