Преглед изворни кода

Updated main app to show how to use updatedDownloadsHandler and the new download methods

Andrea Bizzotto пре 7 година
родитељ
комит
756e9fe48d

+ 8 - 0
SwiftyStoreKit-iOS-Demo/AppDelegate.swift

@@ -33,6 +33,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
 
         completeIAPTransactions()
+        
+        SwiftyStoreKit.updatedDownloadsHandler = { downloads in
+            
+            let finishedDownloadsCount = downloads.filter { $0.downloadState == .finished }.count
+            if finishedDownloadsCount == downloads.count {
+                SwiftyStoreKit.finishTransaction(downloads[0].transaction)
+            }
+        }
 
         return true
     }

+ 5 - 2
SwiftyStoreKit-iOS-Demo/ViewController.swift

@@ -132,7 +132,10 @@ class ViewController: UIViewController {
         SwiftyStoreKit.purchaseProduct(appBundleId + "." + purchase.rawValue, atomically: atomically) { result in
             NetworkActivityIndicatorManager.networkOperationFinished()
 
-            if case .success(let purchase) = result {
+            if case .success(let purchase, let downloads) = result {
+                if !downloads.isEmpty {
+                    SwiftyStoreKit.start(downloads)
+                }
                 // Deliver content from server, then:
                 if purchase.needsFinishTransaction {
                     SwiftyStoreKit.finishTransaction(purchase.transaction)
@@ -267,7 +270,7 @@ extension ViewController {
     // swiftlint:disable cyclomatic_complexity
     func alertForPurchaseResult(_ result: PurchaseResult) -> UIAlertController? {
         switch result {
-        case .success(let purchase):
+        case .success(let purchase, _):
             print("Purchase Success: \(purchase.productId)")
             return nil
         case .error(let error):