|
@@ -45,27 +45,27 @@ class ViewController: NSViewController {
|
|
let Purchase2 = RegisteredPurchase.AutoRenewablePurchase
|
|
let Purchase2 = RegisteredPurchase.AutoRenewablePurchase
|
|
|
|
|
|
// MARK: actions
|
|
// MARK: actions
|
|
- @IBAction func getInfo1(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func getInfo1(_ sender: AnyObject?) {
|
|
getInfo(Purchase1)
|
|
getInfo(Purchase1)
|
|
}
|
|
}
|
|
- @IBAction func purchase1(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func purchase1(_ sender: AnyObject?) {
|
|
purchase(Purchase1)
|
|
purchase(Purchase1)
|
|
}
|
|
}
|
|
- @IBAction func verifyPurchase1(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func verifyPurchase1(_ sender: AnyObject?) {
|
|
verifyPurchase(Purchase1)
|
|
verifyPurchase(Purchase1)
|
|
}
|
|
}
|
|
|
|
|
|
- @IBAction func getInfo2(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func getInfo2(_ sender: AnyObject?) {
|
|
getInfo(Purchase2)
|
|
getInfo(Purchase2)
|
|
}
|
|
}
|
|
- @IBAction func purchase2(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func purchase2(_ sender: AnyObject?) {
|
|
purchase(Purchase2)
|
|
purchase(Purchase2)
|
|
}
|
|
}
|
|
- @IBAction func verifyPurchase2(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func verifyPurchase2(_ sender: AnyObject?) {
|
|
verifyPurchase(Purchase2)
|
|
verifyPurchase(Purchase2)
|
|
}
|
|
}
|
|
|
|
|
|
- func getInfo(purchase: RegisteredPurchase) {
|
|
|
|
|
|
+ func getInfo(_ purchase: RegisteredPurchase) {
|
|
|
|
|
|
SwiftyStoreKit.retrieveProductsInfo([AppBundleId + "." + purchase.rawValue]) { result in
|
|
SwiftyStoreKit.retrieveProductsInfo([AppBundleId + "." + purchase.rawValue]) { result in
|
|
|
|
|
|
@@ -73,7 +73,7 @@ class ViewController: NSViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func purchase(purchase: RegisteredPurchase) {
|
|
|
|
|
|
+ func purchase(_ purchase: RegisteredPurchase) {
|
|
|
|
|
|
SwiftyStoreKit.purchaseProduct(AppBundleId + "." + purchase.rawValue) { result in
|
|
SwiftyStoreKit.purchaseProduct(AppBundleId + "." + purchase.rawValue) { result in
|
|
|
|
|
|
@@ -81,7 +81,7 @@ class ViewController: NSViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @IBAction func restorePurchases(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func restorePurchases(_ sender: AnyObject?) {
|
|
|
|
|
|
SwiftyStoreKit.restorePurchases() { results in
|
|
SwiftyStoreKit.restorePurchases() { results in
|
|
|
|
|
|
@@ -89,7 +89,7 @@ class ViewController: NSViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @IBAction func verifyReceipt(sender: AnyObject?) {
|
|
|
|
|
|
+ @IBAction func verifyReceipt(_ sender: AnyObject?) {
|
|
|
|
|
|
SwiftyStoreKit.verifyReceipt() { result in
|
|
SwiftyStoreKit.verifyReceipt() { result in
|
|
|
|
|
|
@@ -100,12 +100,12 @@ class ViewController: NSViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func verifyPurchase(purchase: RegisteredPurchase) {
|
|
|
|
|
|
+ func verifyPurchase(_ purchase: RegisteredPurchase) {
|
|
|
|
|
|
SwiftyStoreKit.verifyReceipt() { result in
|
|
SwiftyStoreKit.verifyReceipt() { result in
|
|
|
|
|
|
switch result {
|
|
switch result {
|
|
- case .Success(let receipt):
|
|
|
|
|
|
+ case .success(let receipt):
|
|
|
|
|
|
let productId = self.AppBundleId + "." + purchase.rawValue
|
|
let productId = self.AppBundleId + "." + purchase.rawValue
|
|
|
|
|
|
@@ -114,7 +114,7 @@ class ViewController: NSViewController {
|
|
let purchaseResult = SwiftyStoreKit.verifySubscription(
|
|
let purchaseResult = SwiftyStoreKit.verifySubscription(
|
|
productId: productId,
|
|
productId: productId,
|
|
inReceipt: receipt,
|
|
inReceipt: receipt,
|
|
- validUntil: NSDate()
|
|
|
|
|
|
+ validUntil: Date()
|
|
)
|
|
)
|
|
self.showAlert(self.alertForVerifySubscription(purchaseResult))
|
|
self.showAlert(self.alertForVerifySubscription(purchaseResult))
|
|
}
|
|
}
|
|
@@ -126,7 +126,7 @@ class ViewController: NSViewController {
|
|
self.showAlert(self.alertForVerifyPurchase(purchaseResult))
|
|
self.showAlert(self.alertForVerifyPurchase(purchaseResult))
|
|
}
|
|
}
|
|
|
|
|
|
- case .Error(_):
|
|
|
|
|
|
+ case .error(_):
|
|
self.showAlert(self.alertForVerifyReceipt(result))
|
|
self.showAlert(self.alertForVerifyReceipt(result))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -139,18 +139,18 @@ class ViewController: NSViewController {
|
|
// MARK: User facing alerts
|
|
// MARK: User facing alerts
|
|
extension ViewController {
|
|
extension ViewController {
|
|
|
|
|
|
- func alertWithTitle(title: String, message: String) -> NSAlert {
|
|
|
|
|
|
+ func alertWithTitle(_ title: String, message: String) -> NSAlert {
|
|
|
|
|
|
let alert: NSAlert = NSAlert()
|
|
let alert: NSAlert = NSAlert()
|
|
alert.messageText = title
|
|
alert.messageText = title
|
|
alert.informativeText = message
|
|
alert.informativeText = message
|
|
- alert.alertStyle = NSAlertStyle.InformationalAlertStyle
|
|
|
|
|
|
+ alert.alertStyle = NSAlertStyle.informational
|
|
return alert
|
|
return alert
|
|
}
|
|
}
|
|
- func showAlert(alert: NSAlert, handler: ((NSModalResponse) -> Void)? = nil) {
|
|
|
|
|
|
+ func showAlert(_ alert: NSAlert, handler: ((NSModalResponse) -> Void)? = nil) {
|
|
|
|
|
|
- if let window = NSApplication.sharedApplication().keyWindow {
|
|
|
|
- alert.beginSheetModalForWindow(window) { (response: NSModalResponse) in
|
|
|
|
|
|
+ if let window = NSApplication.shared().keyWindow {
|
|
|
|
+ alert.beginSheetModal(for: window) { (response: NSModalResponse) in
|
|
handler?(response)
|
|
handler?(response)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -159,10 +159,10 @@ extension ViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func alertForProductRetrievalInfo(result: SwiftyStoreKit.RetrieveResults) -> NSAlert {
|
|
|
|
|
|
+ func alertForProductRetrievalInfo(_ result: SwiftyStoreKit.RetrieveResults) -> NSAlert {
|
|
|
|
|
|
if let product = result.retrievedProducts.first {
|
|
if let product = result.retrievedProducts.first {
|
|
- let priceString = NSNumberFormatter.localizedStringFromNumber(product.price ?? 0, numberStyle: .CurrencyStyle)
|
|
|
|
|
|
+ let priceString = NumberFormatter.localizedString(from: product.price ?? 0, number: .currency)
|
|
return alertWithTitle(product.localizedTitle ?? "no title", message: "\(product.localizedDescription) - \(priceString)")
|
|
return alertWithTitle(product.localizedTitle ?? "no title", message: "\(product.localizedDescription) - \(priceString)")
|
|
}
|
|
}
|
|
else if let invalidProductId = result.invalidProductIDs.first {
|
|
else if let invalidProductId = result.invalidProductIDs.first {
|
|
@@ -174,31 +174,31 @@ extension ViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func alertForPurchaseResult(result: SwiftyStoreKit.PurchaseResult) -> NSAlert {
|
|
|
|
|
|
+ func alertForPurchaseResult(_ result: SwiftyStoreKit.PurchaseResult) -> NSAlert {
|
|
|
|
|
|
switch result {
|
|
switch result {
|
|
- case .Success(let productId):
|
|
|
|
|
|
+ case .success(let productId):
|
|
print("Purchase Success: \(productId)")
|
|
print("Purchase Success: \(productId)")
|
|
return alertWithTitle("Thank You", message: "Purchase completed")
|
|
return alertWithTitle("Thank You", message: "Purchase completed")
|
|
- case .Error(let error):
|
|
|
|
|
|
+ case .error(let error):
|
|
print("Purchase Failed: \(error)")
|
|
print("Purchase Failed: \(error)")
|
|
switch error {
|
|
switch error {
|
|
- case .Failed(let error):
|
|
|
|
|
|
+ case .failed(let error):
|
|
if error.domain == SKErrorDomain {
|
|
if error.domain == SKErrorDomain {
|
|
return alertWithTitle("Purchase failed", message: "Please check your Internet connection or try again later")
|
|
return alertWithTitle("Purchase failed", message: "Please check your Internet connection or try again later")
|
|
}
|
|
}
|
|
return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
|
|
return alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
|
|
- case .InvalidProductId(let productId):
|
|
|
|
|
|
+ case .invalidProductId(let productId):
|
|
return alertWithTitle("Purchase failed", message: "\(productId) is not a valid product identifier")
|
|
return alertWithTitle("Purchase failed", message: "\(productId) is not a valid product identifier")
|
|
- case .NoProductIdentifier:
|
|
|
|
|
|
+ case .noProductIdentifier:
|
|
return alertWithTitle("Purchase failed", message: "Product not found")
|
|
return alertWithTitle("Purchase failed", message: "Product not found")
|
|
- case .PaymentNotAllowed:
|
|
|
|
|
|
+ case .paymentNotAllowed:
|
|
return alertWithTitle("Payments not enabled", message: "You are not allowed to make payments")
|
|
return alertWithTitle("Payments not enabled", message: "You are not allowed to make payments")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func alertForRestorePurchases(results: SwiftyStoreKit.RestoreResults) -> NSAlert {
|
|
|
|
|
|
+ func alertForRestorePurchases(_ results: SwiftyStoreKit.RestoreResults) -> NSAlert {
|
|
|
|
|
|
if results.restoreFailedProducts.count > 0 {
|
|
if results.restoreFailedProducts.count > 0 {
|
|
print("Restore Failed: \(results.restoreFailedProducts)")
|
|
print("Restore Failed: \(results.restoreFailedProducts)")
|
|
@@ -214,41 +214,41 @@ extension ViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- func alertForVerifyReceipt(result: SwiftyStoreKit.VerifyReceiptResult) -> NSAlert {
|
|
|
|
|
|
+ func alertForVerifyReceipt(_ result: SwiftyStoreKit.VerifyReceiptResult) -> NSAlert {
|
|
|
|
|
|
switch result {
|
|
switch result {
|
|
- case .Success(let receipt):
|
|
|
|
|
|
+ case .success(let receipt):
|
|
print("Verify receipt Success: \(receipt)")
|
|
print("Verify receipt Success: \(receipt)")
|
|
return self.alertWithTitle("Receipt verified", message: "Receipt verified remotly")
|
|
return self.alertWithTitle("Receipt verified", message: "Receipt verified remotly")
|
|
- case .Error(let error):
|
|
|
|
|
|
+ case .error(let error):
|
|
print("Verify receipt Failed: \(error)")
|
|
print("Verify receipt Failed: \(error)")
|
|
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")
|
|
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 alertForVerifySubscription(result: SwiftyStoreKit.VerifySubscriptionResult) -> NSAlert {
|
|
|
|
|
|
+ func alertForVerifySubscription(_ result: SwiftyStoreKit.VerifySubscriptionResult) -> NSAlert {
|
|
|
|
|
|
switch result {
|
|
switch result {
|
|
- case .Purchased(let expiresDate):
|
|
|
|
|
|
+ case .purchased(let expiresDate):
|
|
print("Product is valid until \(expiresDate)")
|
|
print("Product is valid until \(expiresDate)")
|
|
return alertWithTitle("Product is purchased", message: "Product is valid until \(expiresDate)")
|
|
return alertWithTitle("Product is purchased", message: "Product is valid until \(expiresDate)")
|
|
- case .Expired(let expiresDate):
|
|
|
|
|
|
+ case .expired(let expiresDate):
|
|
print("Product is expired since \(expiresDate)")
|
|
print("Product is expired since \(expiresDate)")
|
|
return alertWithTitle("Product expired", message: "Product is expired since \(expiresDate)")
|
|
return alertWithTitle("Product expired", message: "Product is expired since \(expiresDate)")
|
|
- case .NotPurchased:
|
|
|
|
|
|
+ case .notPurchased:
|
|
print("This product has never been purchased")
|
|
print("This product has never been purchased")
|
|
return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- func alertForVerifyPurchase(result: SwiftyStoreKit.VerifyPurchaseResult) -> NSAlert {
|
|
|
|
|
|
+ func alertForVerifyPurchase(_ result: SwiftyStoreKit.VerifyPurchaseResult) -> NSAlert {
|
|
|
|
|
|
switch result {
|
|
switch result {
|
|
- case .Purchased:
|
|
|
|
|
|
+ case .purchased:
|
|
print("Product is purchased")
|
|
print("Product is purchased")
|
|
return alertWithTitle("Product is purchased", message: "Product will not expire")
|
|
return alertWithTitle("Product is purchased", message: "Product will not expire")
|
|
- case .NotPurchased:
|
|
|
|
|
|
+ case .notPurchased:
|
|
print("This product has never been purchased")
|
|
print("This product has never been purchased")
|
|
return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
return alertWithTitle("Not purchased", message: "This product has never been purchased")
|
|
}
|
|
}
|