问题
In app purchases work fine for my iOS side of things. The data from StoreKit is populated as it should. The same code doesn't work on the Mac Catalyst version of the project. I have even created a listing for my Mac app on App Store connect with different bundle identifiers for the in app purchases. I have a print function that returns what product StoreKit found, it works well on iOS, but results with nothing when using Mac Catalyst.
Here is what I have done:
- Make sure that In App purchases has been added in the capabilities section.
- Make sure the Store Kit framework has been imported.
- Make sure the bundle identifiers are correct.
- Make sure all agreements are filled out.
- I am signed out of the Mac App Store.
Code that works on iOS but not on MacOS:
override func viewDidLoad() {
SKPaymentQueue.default().add(self)
let productIds: Set<String> = ["..."]
var request = SKProductsRequest(productIdentifiers: productIds)
request.delegate = self
request.start()
}
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
print("Loaded")
for product in response.products {
print("What came: \(product.productIdentifier) \(product.localizedTitle) \(product.price.floatValue)")}
The iOS app will return with the Product Identifier, Title and Price. The Mac app will return with nothing at all.
回答1:
I found the problem. I had not created a strong reference to my product request.
This line of code fixed my issue:
var request: SKProductsRequest!
来源:https://stackoverflow.com/questions/61802978/in-app-purchase-on-mac-catalyst-not-working