Mercurial > public > simoleon
changeset 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 | b6f8661300f2 |
children | 1069c33d3a42 |
files | Simoleon.xcodeproj/project.pbxproj Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/AppDelegate.swift Simoleon/ContentView.swift Simoleon/ContentViewPad.swift Simoleon/SimoleonApp.swift |
diffstat | 6 files changed, 74 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj Fri Jul 30 15:52:27 2021 +0100 +++ b/Simoleon.xcodeproj/project.pbxproj Sat Jul 31 16:36:01 2021 +0100 @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 950A377726A820F800CAB175 /* DefaultCurrency+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A377626A820F400CAB175 /* DefaultCurrency+CoreDataProperties.swift */; }; 950A377826A820F800CAB175 /* DefaultCurrency+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A377526A820F400CAB175 /* DefaultCurrency+CoreDataClass.swift */; }; + 9522BEA926B5A4D20076B098 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9522BEA826B5A4D20076B098 /* AppDelegate.swift */; }; 9555933A269B0AB8000FD726 /* ParseJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95559339269B0AB8000FD726 /* ParseJson.swift */; }; 95561E3F26AF25EF00CCB543 /* SubscriptionFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95561E3E26AF25EF00CCB543 /* SubscriptionFeature.swift */; }; 95562D4D26A8962A0047E778 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95562D4C26A8962A0047E778 /* StoreKit.framework */; }; @@ -33,7 +34,6 @@ 95B54F4426A4842C001DC0D8 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B54F4326A4842C001DC0D8 /* Conversion.swift */; }; 95B54F4626A48852001DC0D8 /* CurrencySelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B54F4526A48852001DC0D8 /* CurrencySelector.swift */; }; 95B54F4A26A4A450001DC0D8 /* ConversionBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B54F4926A4A450001DC0D8 /* ConversionBox.swift */; }; - 95B54F4F26A4AC52001DC0D8 /* ContentViewPad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B54F4E26A4AC52001DC0D8 /* ContentViewPad.swift */; }; 95B54F5126A4ACAC001DC0D8 /* Sidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B54F5026A4ACAC001DC0D8 /* Sidebar.swift */; }; 95B5F53126AADE4B00BDCE89 /* en.xliff in Resources */ = {isa = PBXBuildFile; fileRef = 95B5F52826AADE4B00BDCE89 /* en.xliff */; }; 95B5F53226AADE4B00BDCE89 /* contents.json in Resources */ = {isa = PBXBuildFile; fileRef = 95B5F52A26AADE4B00BDCE89 /* contents.json */; }; @@ -94,6 +94,7 @@ /* Begin PBXFileReference section */ 950A377526A820F400CAB175 /* DefaultCurrency+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DefaultCurrency+CoreDataClass.swift"; sourceTree = "<group>"; }; 950A377626A820F400CAB175 /* DefaultCurrency+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DefaultCurrency+CoreDataProperties.swift"; sourceTree = "<group>"; }; + 9522BEA826B5A4D20076B098 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 95559339269B0AB8000FD726 /* ParseJson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseJson.swift; sourceTree = "<group>"; }; 95561E3E26AF25EF00CCB543 /* SubscriptionFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionFeature.swift; sourceTree = "<group>"; }; 95562D4C26A8962A0047E778 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; @@ -150,7 +151,6 @@ 95B54F4326A4842C001DC0D8 /* Conversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conversion.swift; sourceTree = "<group>"; }; 95B54F4526A48852001DC0D8 /* CurrencySelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencySelector.swift; sourceTree = "<group>"; }; 95B54F4926A4A450001DC0D8 /* ConversionBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversionBox.swift; sourceTree = "<group>"; }; - 95B54F4E26A4AC52001DC0D8 /* ContentViewPad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewPad.swift; sourceTree = "<group>"; }; 95B54F5026A4ACAC001DC0D8 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; }; 95B5F52826AADE4B00BDCE89 /* en.xliff */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = en.xliff; sourceTree = "<group>"; }; 95B5F52A26AADE4B00BDCE89 /* contents.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = contents.json; sourceTree = "<group>"; }; @@ -328,9 +328,9 @@ children = ( 95E76437269E0033008E9F31 /* Simoleon.entitlements */, 9585BB0F26A6B58500E3193E /* Config.xcconfig */, + 9522BEA826B5A4D20076B098 /* AppDelegate.swift */, 95C5B2272697752600941585 /* SimoleonApp.swift */, 95AEBC9426A03ECB00613729 /* ContentView.swift */, - 95B54F4E26A4AC52001DC0D8 /* ContentViewPad.swift */, 95B54F4326A4842C001DC0D8 /* Conversion.swift */, 95C5179E26A5F34200BC2B24 /* Favorites.swift */, 957065E126A5FE0400523E68 /* Settings.swift */, @@ -574,6 +574,7 @@ 95AEBC9526A03ECB00613729 /* ContentView.swift in Sources */, 95909CB326B07BFC00D051AB /* SearchBar.swift in Sources */, 95AEBC9B26A04A4200613729 /* CurrencyMetadataModel.swift in Sources */, + 9522BEA926B5A4D20076B098 /* AppDelegate.swift in Sources */, 95D8C8CD26A9784500BCC188 /* SubscribeButton.swift in Sources */, 950A377726A820F800CAB175 /* DefaultCurrency+CoreDataProperties.swift in Sources */, 9585BB1A26A6E8FD00E3193E /* SimpleSuccess.swift in Sources */, @@ -588,7 +589,6 @@ 95C517A126A5F6C000BC2B24 /* ResignKeyboard.swift in Sources */, 95AEBC9D26A04D4600613729 /* CurrencyRow.swift in Sources */, 95AEBCA326A0900E00613729 /* CurrencyQuoteModel.swift in Sources */, - 95B54F4F26A4AC52001DC0D8 /* ContentViewPad.swift in Sources */, 9585BB1426A6B7F400E3193E /* NetworkRequest.swift in Sources */, 957065E226A5FE0400523E68 /* Settings.swift in Sources */, 95B54F4426A4842C001DC0D8 /* Conversion.swift in Sources */,
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/AppDelegate.swift Sat Jul 31 16:36:01 2021 +0100 @@ -0,0 +1,35 @@ +// +// AppDelegate.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 31/7/21. +// + +import SwiftUI +import Purchases + +// Add an AppDelegate to a SwiftUI app +class AppDelegate: NSObject, UIApplicationDelegate, PurchasesDelegate { + + // Set delegate to Purchases + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil + ) -> Bool { + Purchases.shared.delegate = self + return true + } + + // Handle purchases started on the App Store + func purchases( + _ purchases: Purchases, + shouldPurchasePromoProduct product: SKProduct, + defermentBlock makeDeferredPurchase: @escaping RCDeferredPromotionalPurchaseBlock + ) { + makeDeferredPurchase { (transaction, purchaserInfo, error, userCancelled) in + if purchaserInfo?.entitlements["all"]?.isActive == true { + print("Subscription purchased from App Store") + } + } + } +}
--- a/Simoleon/ContentView.swift Fri Jul 30 15:52:27 2021 +0100 +++ b/Simoleon/ContentView.swift Sat Jul 31 16:36:01 2021 +0100 @@ -17,26 +17,39 @@ case convert, favorites, settings } + @ViewBuilder var adjustedView: some View { + // MARK: - iPad + if UIDevice.current.userInterfaceIdiom == .pad { + NavigationView { + Sidebar() + Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP") + } + } else { + // MARK: - iPhone + TabView(selection: $tab) { + Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP") + .tabItem { + Label("Convert", systemImage: "arrow.counterclockwise.circle") + } + .tag(Tab.convert) + + Favorites() + .tabItem { + Label("Favorites", systemImage: "star") + } + .tag(Tab.favorites) + + Settings() + .tabItem { + Label("Settings", systemImage: "gear") + } + .tag(Tab.settings) + } + } + } + var body: some View { - TabView(selection: $tab) { - Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP") - .tabItem { - Label("Convert", systemImage: "arrow.counterclockwise.circle") - } - .tag(Tab.convert) - - Favorites() - .tabItem { - Label("Favorites", systemImage: "star") - } - .tag(Tab.favorites) - - Settings() - .tabItem { - Label("Settings", systemImage: "gear") - } - .tag(Tab.settings) - } + adjustedView } }
--- a/Simoleon/ContentViewPad.swift Fri Jul 30 15:52:27 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -// -// ContentViewPad.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 18/07/2021. -// - -import SwiftUI - -struct ContentViewPad: View { - @Environment(\.managedObjectContext) private var viewContext - @FetchRequest(sortDescriptors: []) private var defaultCurrency: FetchedResults<DefaultCurrency> - - var body: some View { - NavigationView { - Sidebar() - Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP") - } - } -} - -struct ContentViewPad_Previews: PreviewProvider { - static var previews: some View { - ContentViewPad() - } -}
--- a/Simoleon/SimoleonApp.swift Fri Jul 30 15:52:27 2021 +0100 +++ b/Simoleon/SimoleonApp.swift Sat Jul 31 16:36:01 2021 +0100 @@ -10,6 +10,7 @@ @main struct SimoleonApp: App { + @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate let persistenceController = PersistenceController.shared init() { @@ -18,14 +19,8 @@ var body: some Scene { WindowGroup { - if UIDevice.current.userInterfaceIdiom == .pad { - ContentViewPad() - .environment(\.managedObjectContext, persistenceController.container.viewContext) - } else { - ContentView() - .environment(\.managedObjectContext, persistenceController.container.viewContext) - } + ContentView() + .environment(\.managedObjectContext, persistenceController.container.viewContext) } } } -