我可以在我的应用中完整购买。但是,当购买完成后,没有任何事情发生,内容未解锁 当我再次点击它时,它会告诉我“您已购买此应用程序内购买但尚未下载”。 因此,从Apple文档中,问题是 finishTransaction:未被调用。
Edit2:完整代码,再次感谢您的帮助
class PurchaseController: UIViewController, SKPaymentTransactionObserver, SKProductsRequestDelegate {
var product: SKProduct = SKProduct()
var productID: NSString = NSString()
var homeViewController: GameScene!
override func viewDidLoad() {
super.viewDidLoad()
}
func getProductInfo(viewController: GameScene) {
homeViewController = viewController
let object: NSSet! = NSSet(object: self.productID)
if (SKPaymentQueue.canMakePayments()) {
let request: SKProductsRequest = SKProductsRequest(productIdentifiers: object)
request.delegate = self
request.start()
}
else {
println("please enbale in app purchase")
}
}
func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
var products: NSArray = response.products
if (products.count != 0) {
product = products[0] as SKProduct
let payment: SKPayment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment)
}
products = response.invalidProductIdentifiers
for product in products {
println("Product not found : \(product)")
}
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
let transaction: SKPaymentTransaction = SKPaymentTransaction()
let transactionPurchased: SKPaymentTransactionState = SKPaymentTransactionState.Purchased
let transactionFailed: SKPaymentTransactionState = SKPaymentTransactionState.Failed
for transaction in transactions {
switch transaction.transactionState {
case transactionPurchased:
self.unlockFeature()
println("transaction OK")
queue.finishTransaction(transaction as SKPaymentTransaction)
case transactionFailed:
println("Transaction failed")
queue.finishTransaction(transaction as SKPaymentTransaction)
default:
println("Transaction problem")
}
}
}
在我的另一堂课中:
class GameScene: SKScene {
var purchaseController: PurchaseController!
//Other code...
override func didMoveToView(view: SKView) {
purchaseController = PurchaseController()
let defaultQueue: SKPaymentQueue = SKPaymentQueue()
defaultQueue.addTransactionObserver(purchaseController)
}
// On a button click
if (nodeAtPoint(location).name == "removeAdLabel") {
purchaseController.productID = "com.appsforyou.rvads"
purchaseController.getProductInfo(self)
}
}
使用断点,对事务队列的添加付款有效,但接下来是paymentQueue:updatedTransactions:似乎没有被调用