I'm using the IAPMaster by rpzzzzz on GitHub - https://github.com/rpzzzzzz/IAPMaster
I've added a consumable in-app purchase to my app on itunesconnect and I gave it a product id "someid".
According to the sample project, I tried to make a purchase -
let iap = IAPMaster.sharedInstance
iap.addPayment(product_id, userIdentifier: nil) { (result) -> () in
switch result{
case .Purchased(let productId,let transaction,let paymentQueue):
print(productId)
print(transaction)
print(paymentQueue)
paymentQueue.finishTransaction(transaction)
case .Failed(let error):
print(error)
default:
break
}
}
When I run this code I get an error -
Error Domain=AddPayment Unknow Product identifier Code=0 "(null)"
How can I fix this error?
Okay. I downloaded and ran the project and found the way to be able to fix the problem. Basically the error you are getting is telling you that you have an unknown product_id
. In the GitHub repo provided by you, there is some sample code that allows you to call the purchase method.
@IBAction func purchase(sender: AnyObject) {
let iap = IAPMaster.sharedInstance
iap.addPayment("your_product_id", userIdentifier: nil) { (result) -> () in
switch result{
case .Purchased(let productId,let transaction,let paymentQueue):
print(productId)
print(transaction)
print(paymentQueue)
paymentQueue.finishTransaction(transaction)
case .Failed(let error):
print(error)
default:
break
}
}
}
Here, you have to replace the your_product_id
with your unique id that you obtained from iTunes Connect. You can therefore see that it is this specific line causing the error as it says:
iap.addPayment("com.irawd.test.30d", userIdentifier: nil) { (result) -> () in ...
addPayment. Once you enter your unique id it runs without a problem and lets you purchase the good. If you'd like to read a really great tutorial about iAPs, here is one from AppCoda.
Hope that helps, Julian!