diff --git a/MasKit/AppStore/Downloader.swift b/MasKit/AppStore/Downloader.swift index c858b0e..1d8ae02 100644 --- a/MasKit/AppStore/Downloader.swift +++ b/MasKit/AppStore/Downloader.swift @@ -12,15 +12,17 @@ import StoreFoundation /// Monitors app download progress. /// /// - Parameter adamId: An app ID? +/// - Parameter purchase: Flag indicating whether the app needs to be purchased. +/// Only works for free apps. Defaults to false. /// - Returns: An error, if one occurred. -func download(_ adamId: UInt64, isPurchase: Bool) -> MASError? { +func download(_ adamId: UInt64, purchase: Bool = false) -> MASError? { guard let account = ISStoreAccount.primaryAccount else { return .notSignedIn } guard let storeAccount = account as? ISStoreAccount else { fatalError("Unable to cast StoreAccount to ISStoreAccount") } - let purchase = SSPurchase(adamId: adamId, account: storeAccount, isPurchase: isPurchase) + let purchase = SSPurchase(adamId: adamId, account: storeAccount, purchase: purchase) var purchaseError: MASError? var observerIdentifier: CKDownloadQueueObserver? diff --git a/MasKit/AppStore/SSPurchase.swift b/MasKit/AppStore/SSPurchase.swift index d4fdcf0..11934b4 100644 --- a/MasKit/AppStore/SSPurchase.swift +++ b/MasKit/AppStore/SSPurchase.swift @@ -13,7 +13,7 @@ typealias SSPurchaseCompletion = (_ purchase: SSPurchase?, _ completed: Bool, _ error: Error?, _ response: SSPurchaseResponse?) -> Void extension SSPurchase { - convenience init(adamId: UInt64, account: ISStoreAccount, isPurchase: Bool) { + convenience init(adamId: UInt64, account: ISStoreAccount, purchase: Bool = false) { self.init() var parameters: [String: Any] = [ @@ -24,7 +24,7 @@ extension SSPurchase { "appExtVrsId": 0 ] - if isPurchase { + if purchase { parameters["macappinstalledconfirmed"] = 1 parameters["pricingParameters"] = "STDQ" @@ -42,7 +42,7 @@ extension SSPurchase { appleID = account.identifier // Not sure if this is needed, but lets use it here. - if isPurchase { + if purchase { isRedownload = false } diff --git a/MasKit/Commands/Install.swift b/MasKit/Commands/Install.swift index 9316db4..f16db8b 100644 --- a/MasKit/Commands/Install.swift +++ b/MasKit/Commands/Install.swift @@ -37,7 +37,7 @@ public struct InstallCommand: CommandProtocol { return nil } - return download(appId, isPurchase: false) + return download(appId) } switch downloadResults.count { diff --git a/MasKit/Commands/Lucky.swift b/MasKit/Commands/Lucky.swift index 46dea83..4d5d84f 100644 --- a/MasKit/Commands/Lucky.swift +++ b/MasKit/Commands/Lucky.swift @@ -73,7 +73,7 @@ public struct LuckyCommand: CommandProtocol { return nil } - return download(appId, isPurchase: false) + return download(appId) } switch downloadResults.count { diff --git a/MasKit/Commands/Purchase.swift b/MasKit/Commands/Purchase.swift index 46dcce0..82c5990 100644 --- a/MasKit/Commands/Purchase.swift +++ b/MasKit/Commands/Purchase.swift @@ -36,7 +36,7 @@ public struct PurchaseCommand: CommandProtocol { return nil } - return download(appId, isPurchase: true) + return download(appId, purchase: true) } switch downloadResults.count { diff --git a/MasKit/Commands/Upgrade.swift b/MasKit/Commands/Upgrade.swift index 589a78f..035999d 100644 --- a/MasKit/Commands/Upgrade.swift +++ b/MasKit/Commands/Upgrade.swift @@ -71,7 +71,7 @@ public struct UpgradeCommand: CommandProtocol { print(updates.map({ "\($0.title) (\($0.bundleVersion))" }).joined(separator: ", ")) let updateResults = updates.compactMap { - download($0.itemIdentifier.uint64Value, isPurchase: false) + download($0.itemIdentifier.uint64Value) } switch updateResults.count {