在app内跳入app store进行评价

1:导入StoreKit.framework,在需要跳转的控制器里面添加头文件 

import  StoreKit

2:实现代理SKStoreProductViewControllerDelegate


代码如下

static let VPNOnITunsIdentifier = "1018221712"  //这个在调用评分页面时候需要使用,请设置为上架app store的真实值,无效值将不会进入回调


// MARK: - UITableViewDelegate

extension AutoConfigViewController: UITableViewDelegate {

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        tableView.deselectRowAtIndexPath(indexPath, animated: true)

        if self.tableView == tableView {

            if indexPath.section == AutoConfigSection.Promotion.hashValue &&

                indexPath.row == AutoConfigPromotionCell.FiveStars.hashValue

            {

                //初始化控制器

                let storeProductViewContorller = SKStoreProductViewController.init()

                //设置代理请求为当前控制器本身

                storeProductViewContorller.delegate = self;

                //appId,注意: 如果值在app store不存在,将不会进入回调

                let productparameters = [SKStoreProductParameterITunesItemIdentifier:AutoConfigViewController.VPNOnITunsIdentifier];

                //加载一个新的视图展示

                storeProductViewContorller.loadProductWithParameters(productparameters, completionBlock: { (success: Bool, error: NSError?) -> Void in

                    //block回调

                    if success == true {//模态弹出AppStore应用界面

                        self.presentViewController(storeProductViewContorller, animated: true, completion: nil);

                    } else {                        

let hud = CommonFunction.showMBProgressHUD(self.view, text: "跳入App Store评分页面失败", detailText: "请稍后再试", isLoading: false)

                        hud.hideAnimated(true, afterDelay: 2)

                    }

                })

            }

        }

    }

}


extension AutoConfigViewController: SKStoreProductViewControllerDelegate {

    func productViewControllerDidFinish(viewController: SKStoreProductViewController) {

        self.dismissViewControllerAnimated(true, completion:{ () -> Void in

            let hud = CommonFunction.showMBProgressHUD(self.view, text: "感谢您的鼓励,我们会再接再砺", detailText: "", isLoading: false)

            hud.hideAnimated(true, afterDelay: 2)

        })

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值