Permalink
Browse files

Clean up AppDelegate

  • Loading branch information...
bizz84 committed Jan 27, 2018
1 parent 9d0694c commit 2dca29394cbcc25d6056078cb6b68bc77e525673
Showing with 12 additions and 10 deletions.
  1. +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)
}
}
}
}

0 comments on commit 2dca293

Please sign in to comment.