我在故事板中启用了一个启用了分页的collectionView。每个集合视图单元格是屏幕的整个宽度
return CGSize(width: collectionView.bounds.width, height: collectionView.bounds.height)
我正在尝试设置IAP并遇到问题。每个单元格都有一个按钮,用于在点击时检查与该行关联的product_ID。
print("About to fetch the product...")
// Can make payments
if (SKPaymentQueue.canMakePayments())
{
let productID:NSSet! = NSSet(object: self.product_ID)
let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
productsRequest.delegate = self
productsRequest.start()
print("Fetching Products")
}else{
print("Can't make purchases")
UIAlertView(title: "Purchases Disabled",
message: "Purchases are disabled on your device! Enable Purchases in the Restriction Settings on your device.",
delegate: nil, cancelButtonTitle: "OK").show()
}
付款队列
func paymentQueue(_ queue: SKPaymentQueue,
updatedTransactions transactions: [SKPaymentTransaction])
{
print("Received Payment Transaction Response from Apple")
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .purchased:
print("Product Purchased")
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
// Handle the purchase
print(product_ID)
UserDefaults.standard.set(true, forKey: product_ID)
setTitle = "Apply Theme"
case .failed:
print("Purchased Failed")
setTitle = "4.99"
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
case .restored:
print("Already Purchased")
//SKPaymentQueue.default().restoreCompletedTransactions()
// Handle the purchase
UserDefaults.standard.set(true, forKey: product_ID)
setTitle = "Apply Theme"
default:
break
}
purchaseButton.setTitle(setTitle, for: .normal)
}
}
}
`
我遇到的问题是,当我按下按钮时,它不返回1个产品ID,它返回3.它处理我选择 和每个相邻单元格的单元格的付款。 即可。似乎即使其他单元格在屏幕外,它们仍然是活动的。它们似乎没有被系统删除。这个问题有方法解决吗?我以前从未遇到过像这样的问题。