I am having difficulty in the logic for making a consumable purchase. Basically I am not sure how to proceed with this function:
private var item: Purchases.Package? {
Items.shared.item
}
Purchases.shared.products(["com.item.id"]) { products in
guard let item = products.first else { return }
Purchases.shared.purchaseProduct(item) { transaction, purchaserInfo, error, cancelled in
// enable some stuff in the app
}
}
public class Items: ObservableObject {
public static let shared = Items()
@Published public var item: Purchases.Package?
init() {
Purchases.shared.products(["com.item.id"]) { products in
self.item = products.first
}
}
}
If I try to initialise like above, it complains that it is a SKProduct?
, and cannot be assigned to Purchases.Package?
.
It looks like you're fetching an Apple SKProduct and trying to assign it to a RevenueCat Package.
You can call the
.purchase()
method directly with the SKProduct.Recommended Approach
It's recommended to use RevenueCat Offerings/Packages since you wouldn't need to hardcode specific product IDs (e.g. "com.item.id") in your app and you can update things remotely.