Browse Source

Clean up AppDelegate

Andrea Bizzotto 7 years ago
parent
commit
2dca29394c
1 changed files with 12 additions and 10 deletions
  1. 12 10
      SwiftyStoreKit-iOS-Demo/AppDelegate.swift

+ 12 - 10
SwiftyStoreKit-iOS-Demo/AppDelegate.swift

@@ -32,20 +32,12 @@ 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)
-            }
-        }
+        setupIAP()
 
         return true
     }
 
-    func completeIAPTransactions() {
+    func setupIAP() {
 
         SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
 
@@ -65,5 +57,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
                 }
             }
         }
+        
+        SwiftyStoreKit.updatedDownloadsHandler = { downloads in
+
+            // contentURL is not nil if downloadState == .finished
+            let contentURLs = downloads.flatMap { $0.contentURL }
+            if contentURLs.count == downloads.count {
+                print("Saving: \(contentURLs)")
+                SwiftyStoreKit.finishTransaction(downloads[0].transaction)
+            }
+        }
     }
 }