iOS应用内打开App Store应用详情界面

转自:http://blog.csdn.net/wave_1102/article/details/8564400

 用iPhone浏览UC浏览器的“应用商店”时,发现可以直接在应用内打开App Store中的应用详情和下载页面。效果如下:



        下面来看看怎么实现这个效果吧。

        苹果官方文档 "SKStoreProductViewController Class Reference"里有如下介绍:

[plain]  view plain copy
  1. A SKStoreProductViewController object presents a store that allows the user to purchase other media from the App Store. For example, your app might display the store to allow the user to purchase another app.  
  2.   
  3. To display a store, create a new SKStoreProductViewController object and set its delegate. Then, present the view controller modally from another view controller in your app. Your delegate dismisses the view controller when the user completes the purchase.  
  4.   
  5. To choose a specific product, call the loadProductWithParameters:completionBlock: method, passing the iTunes item identifier for the item you want to sell.  

        由上可知,通过Modal view方式弹出App Store商品详情页面。我按照文档说明,写了个例子。部分代码如下:

[java]  view plain copy
  1. - (void)openAppWithIdentifier:(NSString *)appId {  
  2.     SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init];  
  3.     storeProductVC.delegate = self;  
  4.       
  5.     NSDictionary *dict = [NSDictionary dictionaryWithObject:appId forKey:SKStoreProductParameterITunesItemIdentifier];  
  6.     [storeProductVC loadProductWithParameters:dict completionBlock:^(BOOL result, NSError *error) {  
  7.         if (result) {  
  8.             [self presentViewController:storeProductVC animated:YES completion:nil];  
  9.         }  
  10.     }];  
  11. }  


另外,需要实现SKStoreProductViewControllerDelegate如下代理方法:

[java]  view plain copy
  1. #pragma mark - SKStoreProductViewControllerDelegate  
  2. - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {  
  3.     [viewController dismissViewControllerAnimated:YES completion:^{  
  4.         [viewController release];  
  5.     }];  
  6. }  


可以这样调用:

[java]  view plain copy
  1. [self openAppWithIdentifier:@"383037733"];  

这段代码即实现了上面图示的效果。

注:项目需要添加StoreKit框架,仅在iOS 6.0以上的设备中支持上述实现。

[java]  view plain copy
  1. Framework     
  2. /System/Library/Frameworks/StoreKit.framework  
  3. Availability      
  4. Available in iOS 6.0 and later.  

如果需要兼容6.0以下的设备,可以使用下面的代码(这种方式会跳出当前应用):

[java]  view plain copy
  1. - (void)outerOpenAppWithIdentifier:(NSString *)appId {  
  2.     NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/us/app/id%@?mt=8", appId];  
  3.     NSURL *url = [NSURL URLWithString:urlStr];  
  4.     [[UIApplication sharedApplication] openURL:url];  
  5. }  


获取应用的链接方法可参考:http://itunes.apple.com/linkmaker

苹果官方文档:http://developer.apple.com/library/ios/#documentation/StoreKit/Reference/SKITunesProductViewController_Ref/Introduction/Introduction.html#//apple_ref/doc/c_ref/SKStoreProductViewController



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值