comparison Simoleon/AppDelegate.swift @ 76:1f657241c28f

Implemented purchases from App Store
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sat, 31 Jul 2021 16:36:01 +0100
parents
children
comparison
equal deleted inserted replaced
75:b6f8661300f2 76:1f657241c28f
1 //
2 // AppDelegate.swift
3 // Simoleon
4 //
5 // Created by Dennis Concepción Martín on 31/7/21.
6 //
7
8 import SwiftUI
9 import Purchases
10
11 // Add an AppDelegate to a SwiftUI app
12 class AppDelegate: NSObject, UIApplicationDelegate, PurchasesDelegate {
13
14 // Set delegate to Purchases
15 func application(
16 _ application: UIApplication,
17 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
18 ) -> Bool {
19 Purchases.shared.delegate = self
20 return true
21 }
22
23 // Handle purchases started on the App Store
24 func purchases(
25 _ purchases: Purchases,
26 shouldPurchasePromoProduct product: SKProduct,
27 defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock
28 ) {
29 makeDeferredPurchase { (transaction, purchaserInfo, error, userCancelled) in
30 if purchaserInfo?.entitlements["all"]?.isActive == true {
31 print("Subscription purchased from App Store")
32 }
33 }
34 }
35 }