-
Notifications
You must be signed in to change notification settings - Fork 45
/
BackyardBirdsShopViewModifier.swift
45 lines (39 loc) · 1.39 KB
/
BackyardBirdsShopViewModifier.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
The shop view modifier.
*/
import SwiftUI
import SwiftData
import BackyardBirdsData
import OSLog
private let logger = Logger(subsystem: "BackyardBirds", category: "BackyardBirdsShopViewModifier")
struct BackyardBirdsShopViewModifier: ViewModifier {
@Environment(\.modelContext) private var modelContext
func body(content: Content) -> some View {
ZStack {
content
}
.subscriptionPassStatusTask()
.onAppear {
logger.info("Creating BirdBrain shared instance")
BirdBrain.createSharedInstance(modelContext: modelContext)
logger.info("BirdBrain shared instance created")
}
.task {
logger.info("Starting tasks to observe transaction updates")
// Begin observing StoreKit transaction updates in case a
// transaction happens on another device.
await BirdBrain.shared.observeTransactionUpdates()
// Check if we have any unfinished transactions where we
// need to grant access to content
await BirdBrain.shared.checkForUnfinishedTransactions()
logger.info("Finished checking for unfinished transactions")
}
}
}
extension View {
func backyardBirdsShop() -> some View {
modifier(BackyardBirdsShopViewModifier())
}
}