No description
Find a file
2025-07-22 01:42:57 -07:00
Sources/KeysForAll Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00
Tests/KeysForAllTests Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00
.gitignore Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00
Package.swift Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00
README.md Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00
VOICEUWU_INTEGRATION_GUIDE.md Initial commit of KeysForAll package 2025-07-22 01:42:57 -07:00

KeysForAll Swift Package

A flexible, reusable Swift package for implementing the Keys for All licensing system in iOS apps.

Features

  • 🔑 Flexible License Levels: Support for Free, Level 1, and Level 2 tiers
  • 🎨 Customizable UI: Provide your own colors and styling
  • 📦 Feature Gating: Easy-to-use API for checking feature availability
  • 💾 Persistent Storage: Built-in UserDefaults storage with protocol for custom implementations
  • 🛒 Purchase Integration: Ready for StoreKit integration
  • 🎁 Key Sharing: Built-in UI for sharing and donating keys

Installation

Swift Package Manager

Add the package dependency to your Package.swift:

dependencies: [
    .package(path: "../path/to/keys-for-all/ios-integration")
]

Or in Xcode:

  1. File > Add Package Dependencies
  2. Click "Add Local..."
  3. Navigate to the keys-for-all/ios-integration directory

Quick Start

1. Define Your Features

import KeysForAll

enum MyAppFeature: String, CaseIterable {
    case premiumThemes
    case advancedFilters
    case exportHighRes
    case batchProcessing
}

class MyAppFeatureProvider: FeatureProvider {
    typealias Feature = MyAppFeature
    
    var allFeatures: [MyAppFeature] {
        MyAppFeature.allCases
    }
    
    func displayName(for feature: MyAppFeature) -> String {
        switch feature {
        case .premiumThemes: return "Premium Themes"
        case .advancedFilters: return "Advanced Filters"
        case .exportHighRes: return "High Resolution Export"
        case .batchProcessing: return "Batch Processing"
        }
    }
    
    func category(for feature: MyAppFeature) -> FeatureCategory {
        switch feature {
        case .premiumThemes: return .visualization
        case .advancedFilters: return .advanced
        case .exportHighRes: return .core
        case .batchProcessing: return .advanced
        }
    }
    
    func requiredLevel(for feature: MyAppFeature) -> LicenseLevel {
        switch feature {
        case .premiumThemes, .advancedFilters: return .level1
        case .exportHighRes, .batchProcessing: return .level2
        }
    }
}

2. Set Up Color Provider

struct MyAppColorProvider: ColorProvider {
    var primaryColor: Color { .blue }
    var secondaryColor: Color { .purple }
    var successColor: Color { .green }
}

3. Initialize in Your App

import SwiftUI
import KeysForAll

@main
struct MyApp: App {
    @StateObject private var keysForAll = KeysForAllManager(
        featureProvider: MyAppFeatureProvider(),
        storage: UserDefaultsKeyStorage(suiteName: "group.myapp")
    )
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(keysForAll)
        }
    }
}

4. Check Feature Availability

struct PremiumFeatureView: View {
    @EnvironmentObject var keysForAll: KeysForAllManager<MyAppFeatureProvider>
    
    var body: some View {
        VStack {
            if keysForAll.isFeatureAvailable(.advancedFilters) {
                AdvancedFiltersView()
            } else {
                LockedFeaturePrompt(feature: .advancedFilters)
            }
            
            // Or use the built-in gated view
            keysForAll.gatedView(for: .batchProcessing) {
                BatchProcessingView()
            } lockedContent: {
                PurchasePromptView()
            }
        }
    }
}

5. Show Keys for All Settings

struct SettingsView: View {
    @EnvironmentObject var keysForAll: KeysForAllManager<MyAppFeatureProvider>
    @StateObject private var purchaseHandler = MyPurchaseHandler()
    
    var body: some View {
        NavigationView {
            List {
                NavigationLink("Keys for All") {
                    KeysForAllView(
                        manager: keysForAll,
                        colorProvider: MyAppColorProvider(),
                        purchaseHandler: purchaseHandler
                    )
                }
            }
        }
    }
}

API Reference

KeysForAllManager

The main class for managing licenses and features.

Properties:

  • keyCount: Current number of keys owned
  • currentLevel: Current license level
  • unlockedFeatures: Set of unlocked features
  • lockedFeatures: Set of locked features

Methods:

  • isFeatureAvailable(_:): Check if a feature is unlocked
  • addKeys(_:): Add keys to the user's account
  • removeKeys(_:): Remove keys (for sharing/donating)
  • gatedView(for:content:lockedContent:): SwiftUI view builder for conditional content

Protocols

FeatureProvider: Define your app's features

  • allFeatures: Array of all features
  • displayName(for:): Human-readable name
  • category(for:): Feature category
  • requiredLevel(for:): Required license level

ColorProvider: Customize UI colors

  • primaryColor: Main brand color
  • secondaryColor: Secondary brand color
  • successColor: Success state color

KeyStorage: Implement custom storage

  • getKeyCount(): Retrieve key count
  • setKeyCount(_:): Store key count
  • isKeyGatingEnabled(): Check if gating is active

Testing

The package includes a debug mode that can be enabled by setting isKeyGatingEnabled to false, which unlocks all features regardless of key count.

License

This package is part of the Keys for All system. See LICENSE for details.