要将用户推送到iTunes商店以获取所需的项目,我正在使用以下功能:
func openStoreProductWithiTunesItemIdentifier(identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self
let parameters = [ SKStoreProductParameterITunesItemIdentifier : identifier, SKStoreProductParameterAffiliateToken : ITUNES_AFFILIATE_ID]
storeViewController.loadProductWithParameters(parameters) { [weak self] (loaded, error) -> Void in
if loaded {
self!.navigationController?.pushViewControllerWithHandler(storeViewController, animated: true) {
LilithProgressHUD.hide() // custom progress hud
}
}
}
}
extension UINavigationController {
func pushViewControllerWithHandler(viewController: UIViewController, animated: Bool, completion: Void -> Void) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
pushViewController(viewController, animated: animated)
CATransaction.commit()
}
}
Run Code Online (Sandbox Code Playgroud)
叫做
let trackID = "thisIsMyTrackID"
openStoreProductWithiTunesItemIdentifier(trackID)
Run Code Online (Sandbox Code Playgroud)
这导致了
如果我不是:
self!.navigationController?.pushViewControllerWithHandler(storeViewController, animated: true) { …Run Code Online (Sandbox Code Playgroud)