InAppPurchase: Download hosted content from AppDelegate

215 Views Asked by At

I m trying to implement In App Purchase with hosted content in Apple's servers. I'm using the SwiftyStoreKit framework.

Usually, according to the others tutorials, we need to implement the downloading call in : func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

So i have implemented the following code in this func:

let downloads = transaction.downloads
SKPaymentQueue.defaultQueue().startDownloads(downloads)

It's working, and now i m trying in the AppDelegate to check if the statut of a previous transaction is "purchased" but not "finished". That means user has bought the product, but there was an issue with the downloading.

Here s my code.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    completeIAPTransactions()
    return true
}

func completeIAPTransactions() {
    SwiftyStoreKit.completeTransactions(atomically: false) { products in
        for product in products {
            if product.transaction.transactionState == .purchased || product.transaction.transactionState == .restored {
                if product.needsFinishTransaction {
                    // Deliver content from server, then:


                    let downloads = transaction.downloads
                    SKPaymentQueue.defaultQueue().startDownloads(downloads)

                    SwiftyStoreKit.finishTransaction(product.transaction)
                }
                print("purchased: \(product.productId)")
            }
        }
    }
}

The checking is working, but there s an issue with the downloading :

Value of type PaymentTransaction has no member downloads.

The question is : how could i properly launching the downloading of the content when i m not in the paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])

Any help will be appreciated.

1

There are 1 best solutions below

0
On

If anyone stumbles on this problem you need to download the master branch from the repo instead of relying on cocoapods.

pod 'SwiftyStoreKit', :git => "https://github.com/bizz84/SwiftyStoreKit.git"

The reason for the error is that for some reason not all the files get copied over when pod install is run. It could be that there's cached version somewhere on your machine.