我正在尝试将应用内购买添加到我的iOS应用中。我按照教程编写了以下代码:
import UIKit
import StoreKit
let secondViewController: SKStoreProductViewController = SKStoreProductViewController();
class GameViewController: UIViewController, UITextFieldDelegate, GKGameCenterControllerDelegate, SKStoreProductViewControllerDelegate{
func buycoin(){
println("buycoin")
secondViewController.delegate = self
var someitunesid:String = "coin200a"
var productparameters = [SKStoreProductParameterITunesItemIdentifier: someitunesid]
secondViewController.loadProductWithParameters(productparameters, {
(success:Bool!, error: NSError!) -> Void in
if success == true{
self.presentViewController(secondViewController, animated: true, completion: nil)
println("succes")
}
else{
NSLog("%@", error)
println("nosucces")
}
})
}
func productViewControllerDidFinish(viewController: SKStoreProductViewController!) {
secondViewController.dismissViewControllerAnimated(true, completion: nil)
}
}
此代码工作正常。当函数buycoin()
激活时,我只在控制台中打印buycoin
,没有别的。
我做错了什么?