Skip to content

muthuselvamlms/AgeRangeKit

Repository files navigation

## 🧠 **AgeRangeKit**

Drop-in mock for Apple’s DeclaredAgeRange API — works on simulator and older iOS versions.

A hybrid compatibility wrapper and mock framework for Apple’s DeclaredAgeRange API.
It allows developers to build, test, and run apps that depend on Apple’s age-gating framework — even on Simulators, older iOS versions, and VisionOS, while automatically using the real system API when available.


⚙️ Why AgeRangeKit?

Apple introduced DeclaredAgeRange to enforce age gating under US privacy law.
However, it’s not available on Simulators, older OS versions, or VisionOS.
That makes local testing and CI workflows painful.

AgeRangeKit fixes that.

  • Works in production and development.
  • Fallback mock behavior for unsupported devices.
  • Seamless switch to the Apple API when available.
  • UI for DOB entry, sharing preferences, and parental control simulation.

🧩 Installation

🟦 Swift Package Manager

In Xcode:

File → Add Packages → https://github.com/muthuselvam/AgeRangeKit.git

Or add this to your Package.swift:

.package(url: "https://github.com/muthuselvam/AgeRangeKit.git", from: "1.0.0")

☕️ CocoaPods

Add to your Podfile:

pod 'AgeRangeKit', :git => 'https://github.com/muthuselvam/AgeRangeKit.git'

Then run:

pod install

🧪 Usage

Import

import AgeRangeKit

Request an age range

do {
    let response = try await AgeRangeService.shared.requestAgeRange(ageGates: 13, 15, 18, in: window)
    switch response {
    case .sharing(let range):
        print("User is \(range.lowerBound ?? 0)+ years old")
    case .declinedSharing:
        print("User declined to share their age range.")
    }
} catch {
    print("Error requesting age range: \(error)")
}

Use MockAgeRangeProvider for unit testing

let mock = MockAgeRangeProvider(initialScenario: .sharingTeen)
let service = AgeRangeService(mock)
let response = try await service.requestAgeRange(ageGates: 13, in: window)

🧰 SwiftUI Integration

AgeRangeKit also supports the SwiftUI @Environment pattern:

@Environment(\.requestAgeRange) var requestAgeRange

Button("Check Age") {
    Task {
        let response = try await requestAgeRange(13, 15, 18, window)
        print(response)
    }
}

🏗️ Architecture

Layer Description
AgeRangeService Public API identical to Apple’s DeclaredAgeRange service.
AppleAgeRangeProvider Delegates to Apple’s native DeclaredAgeRange on supported OS.
MockAgeRangeProvider Developer testing mock — simulates every possible scenario instantly.

📚 Scenarios via MockAgeRangeProvider

Scenario Result
.sharingChild Age < 13, with parental controls.
.sharingTeen Age between 13–17.
.sharingAdult Age ≥ 18.
.declinedSharing User denies sharing.
.errorNotAvailable Simulates unavailable system.
.errorInvalidRequest Simulates malformed request.
.errorUnknown Generic fallback error.

🧾 License

MIT License © 2025 Muthu L

About

A cross-platform Swift framework that mirrors Apple’s DeclaredAgeRange API — with simulator, pre-iOS 26, pre-macOS 26, and visionOS support via a seamless mock fallback.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors