-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d95cba
commit 339e624
Showing
18 changed files
with
1,041 additions
and
1 deletion.
There are no files selected for viewing
Submodule InAppPurchaseManager
deleted from
393d34
Binary file not shown.
386 changes: 386 additions & 0 deletions
386
examples/InAppPurchaseManager/InAppPurchaseManager.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...rchaseManager/InAppPurchaseManager.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
.../InAppPurchaseManager.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+29.9 KB
...oj/project.xcworkspace/xcuserdata/wangchujiang.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
81 changes: 81 additions & 0 deletions
81
...nager/InAppPurchaseManager.xcodeproj/xcshareddata/xcschemes/InAppPurchaseManager.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1540" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "7D4C0A5F2C3ED21B0050CB10" | ||
BuildableName = "InAppPurchaseManager.app" | ||
BlueprintName = "InAppPurchaseManager" | ||
ReferencedContainer = "container:InAppPurchaseManager.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "7D4C0A5F2C3ED21B0050CB10" | ||
BuildableName = "InAppPurchaseManager.app" | ||
BlueprintName = "InAppPurchaseManager" | ||
ReferencedContainer = "container:InAppPurchaseManager.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<StoreKitConfigurationFileReference | ||
identifier = "../../Product.storekit"> | ||
</StoreKitConfigurationFileReference> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "7D4C0A5F2C3ED21B0050CB10" | ||
BuildableName = "InAppPurchaseManager.app" | ||
BlueprintName = "InAppPurchaseManager" | ||
ReferencedContainer = "container:InAppPurchaseManager.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
22 changes: 22 additions & 0 deletions
22
...eManager.xcodeproj/xcuserdata/wangchujiang.xcuserdatad/xcschemes/xcschememanagement.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>SchemeUserState</key> | ||
<dict> | ||
<key>InAppPurchaseManager.xcscheme_^#shared#^_</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>0</integer> | ||
</dict> | ||
</dict> | ||
<key>SuppressBuildableAutocreation</key> | ||
<dict> | ||
<key>7D4C0A5F2C3ED21B0050CB10</key> | ||
<dict> | ||
<key>primary</key> | ||
<true/> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
11 changes: 11 additions & 0 deletions
11
...ppPurchaseManager/InAppPurchaseManager/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...nAppPurchaseManager/InAppPurchaseManager/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/InAppPurchaseManager/InAppPurchaseManager/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/InAppPurchaseManager/InAppPurchaseManager/ContentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// ContentView.swift | ||
// InAppPurchaseManager | ||
// | ||
// Created by 王楚江 on 2024/7/10. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@EnvironmentObject private var entitlement: EntitlementManager | ||
@State var showingSubscriptionView = false | ||
var body: some View { | ||
VStack { | ||
if entitlement.hasPro == false { | ||
Button("Subscription Purchase") { | ||
showingSubscriptionView.toggle() | ||
} | ||
} else { | ||
Text("You have subscribed to purchase") | ||
} | ||
} | ||
.padding() | ||
.sheet(isPresented: $showingSubscriptionView) { | ||
SubscriptionView() | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/InAppPurchaseManager/InAppPurchaseManager/InAppPurchaseManager.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
27 changes: 27 additions & 0 deletions
27
examples/InAppPurchaseManager/InAppPurchaseManager/InAppPurchaseManagerApp.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// InAppPurchaseManagerApp.swift | ||
// InAppPurchaseManager | ||
// | ||
// Created by 王楚江 on 2024/7/10. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct InAppPurchaseManagerApp: App { | ||
@StateObject private var entitlementManager: EntitlementManager | ||
@StateObject private var subscriptionsManager: SubscriptionsManager | ||
init() { | ||
let entitlement = EntitlementManager() | ||
let subscriptions = SubscriptionsManager(entitlementManager: entitlement) | ||
self._entitlementManager = StateObject(wrappedValue: entitlement) | ||
self._subscriptionsManager = StateObject(wrappedValue: subscriptions) | ||
} | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
.environmentObject(entitlementManager) | ||
.environmentObject(subscriptionsManager) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...urchaseManager/InAppPurchaseManager/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
examples/InAppPurchaseManager/InAppPurchaseManager/SubscriptionView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// SubscriptionView.swift | ||
// InAppPurchaseManager | ||
// | ||
// Created by 王楚江 on 2024/7/10. | ||
// | ||
|
||
import SwiftUI | ||
import StoreKit | ||
|
||
struct SubscriptionView: View { | ||
@Environment(\.dismiss) var dismiss | ||
@EnvironmentObject private var subscriptions: SubscriptionsManager | ||
@State private var message: String = "" | ||
let privacyPolicy = URL(string: "https://wangchujiang.com/copybook-generator/privacy-policy.html")! | ||
let termsOfService = URL(string: "https://wangchujiang.com/copybook-generator/terms-of-service.html")! | ||
var body: some View { | ||
if !subscriptions.products.isEmpty { | ||
VStack { | ||
SubscriptionStoreView(productIDs: subscriptions.productIDs) | ||
.storeButton(.visible, for: .policies) | ||
.subscriptionStorePolicyDestination(url: privacyPolicy, for: .privacyPolicy) | ||
.subscriptionStorePolicyDestination(url: termsOfService, for: .termsOfService) | ||
.onInAppPurchaseCompletion(perform: { product, result in | ||
if case .success(.success(let transaction)) = result { | ||
print("Purchased successfully: \(transaction.signedDate)") | ||
await subscriptions.updatePurchasedProducts() | ||
dismiss() | ||
} else { | ||
print("Something else happened") | ||
} | ||
}) | ||
Button(action: { | ||
Task { | ||
await subscriptions.restorePurchases() | ||
dismiss() | ||
} | ||
}, label: { | ||
Text("Restore Subscription") | ||
}) | ||
#if os(macOS) | ||
.buttonStyle(.link) | ||
#endif | ||
.offset(y: -22) | ||
} | ||
.background(.background) | ||
.frame(minWidth: 320, minHeight: 580) | ||
.frame(maxWidth: 450) | ||
} else { | ||
VStack { | ||
if message.isEmpty { | ||
ProgressView().progressViewStyle(.circular).scaleEffect(1).ignoresSafeArea(.all) | ||
} else { | ||
Text(message).foregroundStyle(.red) | ||
} | ||
} | ||
.padding(.horizontal) | ||
.frame(minWidth: 230, minHeight: 120) | ||
} | ||
} | ||
} |
Oops, something went wrong.