我的VC喜欢这样:
var coins = 50 // coins
override func viewDidLoad() {
super.viewDidLoad()
if(SKPaymentQueue.canMakePayments()) {
//print("enabled, loading")
let productID: NSSet = NSSet(objects: "com.tahabuyruk.taha.coinsal", "com.tahabuyruk.taha.reklam") // my products Id
let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
} else {
print("please enable IAPS")
}
}
//I have 2 products on itunesconnect
@IBAction func btnRemoveAds(_ sender: Any) {
print("rem ads")
for product in list {
let prodID = product.productIdentifier
if(prodID == "com.tahabuyruk.taha.reklam") {
// ad product id
p = product
buyProduct()
}
}
}
// my bundle id is com.tahabuyruk.taha
// my product id is com.tahabuyruk.taha.coins
@IBAction func satinAl(_ sender: Any) { // addCoin Button
for product in list {
let prodID = product.productIdentifier
if(prodID == "com.tahabuyruk.taha.coinsal") {
p = product
buyProduct()
}
}
}
func buyProduct() {
print("buy " + p.productIdentifier)
let pay = SKPayment(product: p)
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().add(pay as SKPayment)
}
func removeAds() {
lblAd.removeFromSuperview()
}
func addCoins() {
coins += 50
lblCoinAmount.text = "\(coins)"
}
var list = [SKProduct]()
var p = SKProduct()
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
print("product request")
let myProduct = response.products // myProduct is always be 0 . I don't know why .
for product in myProduct {
print("product added")
print(product.productIdentifier)
print(product.localizedTitle)
print(product.localizedDescription)
print(product.price)
list.append(product)
}
}
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
print("transactions restored")
for transaction in queue.transactions {
let t: SKPaymentTransaction = transaction
let prodID = t.payment.productIdentifier as String
switch prodID {
case "com.tahabuyruk.taha.reklam":// ad product id
print("remove ads")
removeAds()
case "com.tahabuyruk.taha.coinsal":
print("add coins to account")
addCoins()
default:
print("IAP not found")
}
}
}
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
print("add payment")
for transaction: AnyObject in transactions {
let trans = transaction as! SKPaymentTransaction
print(trans.error)
switch trans.transactionState {
case .purchased:
print("buy ok")
print(p.productIdentifier)
let prodID = p.productIdentifier
switch prodID {
case "com.tahabuyruk.taha.reklam":// ad product id
print("remove ads")
removeAds()
case "com.tahabuyruk.taha.coinsal":
print("add coins to account")
addCoins()
default:
print("IAP not found")
}
queue.finishTransaction(trans)
case .failed:
print("buy error")
queue.finishTransaction(trans)
break
default:
print("Default")
break
}
}
}
始终myProduct为0。 这段代码有什么问题? 我想知道为什么总是0?
答案 0 :(得分:0)
我处理此问题,寻找协议,税务和银行业务,并检查您的银行,联系方式和税务信息是否已填写