|
@@ -33,16 +33,8 @@ enum RegisteredPurchase : String {
|
|
|
case NonConsumablePurchase = "nonConsumablePurchase"
|
|
|
case ConsumablePurchase = "consumablePurchase"
|
|
|
case AutoRenewablePurchase = "autoRenewablePurchase"
|
|
|
+ case NonRenewingPurchase = "nonRenewingPurchase"
|
|
|
|
|
|
- var purchaseType: SwiftyStoreKit.PurchaseType {
|
|
|
- switch self {
|
|
|
- case .Purchase1: return .NonConsumable
|
|
|
- case .Purchase2: return .NonConsumable
|
|
|
- case .NonConsumablePurchase: return .NonConsumable
|
|
|
- case .ConsumablePurchase: return .Consumable
|
|
|
- case .AutoRenewablePurchase: return .AutomaticallyRenewableSubscription(validUntilDate: NSDate())
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
class ViewController: NSViewController {
|
|
@@ -115,13 +107,25 @@ class ViewController: NSViewController {
|
|
|
switch result {
|
|
|
case .Success(let receipt):
|
|
|
|
|
|
- let purchaseResult = SwiftyStoreKit.verifyPurchase(
|
|
|
- productId: self.AppBundleId + "." + purchase.rawValue,
|
|
|
- inReceipt: receipt,
|
|
|
- purchaseType: purchase.purchaseType
|
|
|
- )
|
|
|
- self.showAlert(self.alertForVerifyPurchase(purchaseResult))
|
|
|
+ let productId = self.AppBundleId + "." + purchase.rawValue
|
|
|
|
|
|
+ // Specific behaviour for AutoRenewablePurchase
|
|
|
+ if purchase == .AutoRenewablePurchase {
|
|
|
+ let purchaseResult = SwiftyStoreKit.verifySubscription(
|
|
|
+ productId: productId,
|
|
|
+ inReceipt: receipt,
|
|
|
+ validUntil: NSDate()
|
|
|
+ )
|
|
|
+ self.showAlert(self.alertForVerifySubscription(purchaseResult))
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ let purchaseResult = SwiftyStoreKit.verifyPurchase(
|
|
|
+ productId: productId,
|
|
|
+ inReceipt: receipt
|
|
|
+ )
|
|
|
+ self.showAlert(self.alertForVerifyPurchase(purchaseResult))
|
|
|
+ }
|
|
|
+
|
|
|
case .Error(_):
|
|
|
self.showAlert(self.alertForVerifyReceipt(result))
|
|
|
}
|
|
@@ -221,21 +225,33 @@ extension ViewController {
|
|
|
return self.alertWithTitle("Receipt verification failed", message: "The application will exit to create receipt data. You must have signed the application with your developer id to test and be outside of XCode")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func alertForVerifyPurchase(result: SwiftyStoreKit.VerifyPurchaseResult) -> NSAlert {
|
|
|
+
|
|
|
+ func alertForVerifySubscription(result: SwiftyStoreKit.verifySubscriptionResult) -> NSAlert {
|
|
|
|
|
|
switch result {
|
|
|
case .Purchased(let expiresDate):
|
|
|
- if let expiresDate = expiresDate {
|
|
|
- return alertWithTitle("Product is purchased", message: "Product is valid until \(expiresDate)")
|
|
|
- }
|
|
|
- return alertWithTitle("Product is purchased", message: "Product will not expire")
|
|
|
- case .Expired(let expiresDate): // Only for Automatically Renewable Subscription
|
|
|
+ print("Product is valid until \(expiresDate)")
|
|
|
+ return alertWithTitle("Product is purchased", message: "Product is valid until \(expiresDate)")
|
|
|
+ case .Expired(let expiresDate):
|
|
|
+ print("Product is expired since \(expiresDate)")
|
|
|
return alertWithTitle("Product expired", message: "Product is expired since \(expiresDate)")
|
|
|
case .NotPurchased:
|
|
|
+ print("This product has never been purchased")
|
|
|
return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ func alertForVerifyPurchase(result: SwiftyStoreKit.VerifyPurchaseResult) -> NSAlert {
|
|
|
+
|
|
|
+ switch result {
|
|
|
+ case .Purchased:
|
|
|
+ print("Product is purchased")
|
|
|
+ return alertWithTitle("Product is purchased", message: "Product will not expire")
|
|
|
+ case .NotPurchased:
|
|
|
+ print("This product has never been purchased")
|
|
|
+ return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|