iOS通过SKStoreProductViewController 在app中直接访问app store 不需要跳转到app store

首先 import StoreKit

StoreKit 中的 SKStoreProductViewControllerapp store提供的方法

官方文档

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. 

添加代理 SKStoreProductViewControllerDelegate

import StoreKit.SKStoreProductViewController

//访问代码段

    func showStore(id:Int) {

        let storeViewController = SKStoreProductViewController()

        storeViewController.delegate = self

        let parameters = [SKStoreProductParameterITunesItemIdentifier :

            NSNumber(integer: id)]

        storeViewController.loadProductWithParameters(parameters,

            completionBlock: {result, error in

                if result {

                    self.presentViewController(storeViewController,

                        animated: true, completion: nil)

                    // remove loading animation

                }

        })

    }

//结束访问代码段

    func productViewControllerDidFinish(viewController: SKStoreProductViewController) {

        viewController.dismissViewControllerAnimated(true, completion: nil)

        self.bottomToolbar.hidden = false

    }

posted on 2016-07-25 21:10  LouisQian  阅读(751)  评论(0编辑  收藏  举报

导航