### Initialize AmoreLicensing Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Create an instance of AmoreLicensing using your public licensing key. All methods on AmoreLicensing throw AmoreError. ```swift let licensing = try AmoreLicensing( publicKey: "sa92JNtsaYefYp0MIWQbKu1hpS9bSN89ta7b8mlPbI8=" ) ``` -------------------------------- ### Initialize and Activate License Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Initialize AmoreLicensing with a public key and activate a license using a license key. ```swift import AmoreLicensing // Initialize with your Ed25519 public key from Amore let licensing = try AmoreLicensing(publicKey: "your-ed25519-public-key") // Activate a license try await licensing.activate(licenseKey: "XXXX-XXXX-XXXX-XXXX") ``` -------------------------------- ### Initialize AmoreStore Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Create an instance of AmoreStore to begin interacting with the store. It defaults to using your app's bundle identifier. ```swift let store = AmoreStore() ``` -------------------------------- ### Configure Licensing with Grace Period and Validation Frequency Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Initialize AmoreLicensing with custom configuration for grace period and validation frequency. ```swift let licensing = try AmoreLicensing( publicKey: "your-key", configuration: LicensingConfiguration( gracePeriod: .days(7), // How long to allow usage after token expiry validationFrequency: .weekly // Staleness threshold before validate() refreshes from the server ) ) ``` -------------------------------- ### Fetch Products from AmoreStore Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Call the products() method on an AmoreStore instance to retrieve all products configured for your application. This operation can throw a StoreError. ```swift let products = try await store.products() ``` -------------------------------- ### Add AmoreKit to Package.swift Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Integrate AmoreKit into your project's Package.swift file by specifying the package URL and version. ```swift .package(url: "https://github.com/AmoreComputer/AmoreKit", from: "0.1") ``` -------------------------------- ### Add AmoreKit Package to Xcode Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Add the AmoreKit package to your Xcode project by providing the repository URL in the 'Add Package Dependencies' dialog. ```text https://github.com/AmoreComputer/AmoreKit ``` -------------------------------- ### Open Stripe Checkout URL Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Use NSWorkspace.shared.open() to direct the user to the product's checkoutURL for completing the purchase via Stripe. ```swift NSWorkspace.shared.open(product.checkoutURL) ``` -------------------------------- ### Display Product Prices in SwiftUI Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreStore/Documentation.docc/Getting Started.md Iterate through fetched products and display their names and localized prices. Use displayPrice for formatted price strings and recurringInterval to distinguish subscriptions. ```swift ForEach(products) { product in HStack { Text(product.name) Spacer() if let displayPrice = product.displayPrice { Text(displayPrice) } } } ``` -------------------------------- ### Define Entitlements using Static Constants Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Define custom entitlements as static constants conforming to License.Entitlement for checking feature access. ```swift extension License.Entitlement { static let pro: Self = "pro" static let teams: Self = "teams" } ``` -------------------------------- ### Observe License Status in SwiftUI Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Reactively observe the license status in a SwiftUI view. Handles valid, grace period, invalid, and unknown states. ```swift import AmoreLicensing // Observe status reactively in SwiftUI struct ContentView: View { @State var licensing: AmoreLicensing var body: some View { switch licensing.status { case .valid(let license): Text("Licensed to \(license.name)") case .gracePeriod(let license): Text("License expired — grace period until \(license.expiresAt!)") case .invalid: Text("License invalid") case .unknown: Text("No license") } } } ``` -------------------------------- ### Observe License Status Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Observe the current status of the license, which can be valid, invalid, in a grace period, or unknown. This uses the Observation framework. ```swift switch licensing.status { case .valid(let license): print("License is valid") case .invalid: print("License is invalid") case .gracePeriod(let license): print("Grace period until \(endDate)") case .unknown: print("License status unknown") } ``` -------------------------------- ### Check License Entitlements Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Check if a valid license grants specific features or access levels using the validate method. ```swift if case .valid(let license) = licensing.status { let hasPro = license.validate(entitlement: .pro) let hasTeams = license.validate(entitlement: AppEntitlement.teams) } ``` -------------------------------- ### Manually Validate License Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Manually trigger a license validation check against the server. ```swift try await licensing.validate() ``` -------------------------------- ### Validate License on App Activation Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Continuously validate the license when the app becomes active to ensure it remains fresh. This snippet uses SwiftUI's onChange and Observation framework. ```swift .onChange(of: scenePhase) { _, phase in if phase == .active { Task { try? await licensing.validate() } } } ``` -------------------------------- ### Validate Entitlement using String Literals Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Check if a license has a specific entitlement using string literal extensions. ```swift // Using string literals extension License.Entitlement { static let pro: Self = "pro" static let teams: Self = "teams" } if case .valid(let license) = licensing.status { if license.validate(entitlement: .pro) { // Unlock pro features } } ``` -------------------------------- ### Define Entitlements using a Custom Enum Source: https://github.com/amorecomputer/amorekit/blob/main/Sources/AmoreLicensing/Documentation.docc/Getting Started.md Define custom entitlements using a Swift enum that conforms to the EntitlementProtocol. ```swift enum AppEntitlement: String, EntitlementProtocol { case pro, teams } ``` -------------------------------- ### Deactivate License Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Deactivates the current license. ```swift try await licensing.deactivate() ``` -------------------------------- ### Validate Entitlement using Typed Enum Source: https://github.com/amorecomputer/amorekit/blob/main/readme.md Check if a license has a specific entitlement using a typed enum conforming to EntitlementProtocol. ```swift enum AppEntitlement: String, EntitlementProtocol { case pro, teams } license.validate(entitlement: AppEntitlement.pro) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.