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)
})
}
}