Where to find sample code for SB2420 compliance and questions

I'm struggling to implement required code for SB2420 compliance.

I try to learn on a very simple use case.

  • the app is UIKit
  • Build in Xcode 26.2
  • it displays a single Hello view with a button that will simply show a "Good day" label.

I assume the app will be rated 4+.

I tried the following code, using available information in Xcode (limited):

import UIKit
import DeclaredAgeRange
// other import needed ?

class ViewController: UIViewController {

    @IBOutlet weak var welcomeLabel: UILabel!  // initially hidden
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    func testAgeRange() -> Bool {
        if !isEligibleForAgeFeatures { // Not found. Which import needed ?
            return true // Not called from Texas
        }
        // Following code from Xcode doc…
        do {
            let response = try await AgeRangeService.shared.requestAgeRange(ageGates: 13, 15, 18) // Compiler Error: Missing argument for parameter 'in' in call
            // Can I add the 4 gate ?
            guard let lowerBound = response.lowerBound else {
                // Allow access to under 13 features.
                return false
            }
            
            var ok = false

            if lowerBound >= 18 { // Not needed ?
                // Allow access to 18+ features.
                ok = true
            } else if lowerBound >= 15 { // Not needed ?
                // Allow access to 15+ features.
                ok = true
            } else if lowerBound >= 13 { // Not needed ?
                // Require parental consent ?
                // Allow access to 13+ features.
                ok = true // if consent OK
            } else  {
                // Require parental consent ?
                // Show age-appropriate content
                ok = true // if consent OK
            }
            return ok // Authorized for all 4+

        } catch AgeRangeService.Error.notAvailable {
           // No age range provided.
           return false
        }
    }

    func executeStart() {
        welcomeLabel.isHidden = false
    }
    
    @IBAction func start(_ sender: UIButton) {
        
        if #available(iOS 26.0, *) {
            if testAgeRange() {
                // Need to test for parental control here ?
            } else {
                // Alert and exit the app ?
            }
            
        } else {
            // do nothing ? Can we run the app ?
        }
        executeStart()
    }
    
}

The logic would be:

before allowing action with the start button, check

  • is it IOS 26+ so that we can call API
  • if so, is verification needed (Texas SB2420)
  • if not, we can proceed
  • if required, test age range
  • As app is 4+, all ranges should be OK
  • But need to test parental control

Now, many pending questions in code:

  • line 14: get an error: Cannot find 'isEligibleForAgeFeatures' in scope
  • line 19: I used the documentation sample for AgeRangeService, but get a Compiler Error: Missing argument for parameter 'in' in call
  • line 35: how to implement parental control ?

In addition, in the metadata of the app, should I declare that parental control ?

Age verification?
Mechanism for confirming that a person's age meets the age requirement for accessing content or services

As there is no restriction on age, is it required ?

Any help welcomed as well as link to a comprehensive tutorial.

line 19: I used the documentation sample for AgeRangeService, but get a Compiler Error: Missing argument for parameter 'in' in call

That was for SwiftUI.

For UIKit, require in parameter.

So code reformatted. Removes all errors except unknown isEligibleForAgeFeatures.

All other questions remain.

    func testAgeRange() async -> Bool {
        if !isEligibleForAgeFeatures { // Which import needed ?
            return true // Not called from Texas
        }
        
        do {
            let response = try await AgeRangeService.shared.requestAgeRange(ageGates: 13, 15, 18, in: self) 
            // Can I use the 4 gate instead ? ageGates: 4, 13, 18
//            guard let lowerBound = response.lowerBound else {
//                // Allow access to under 13 features.
//                return false
//            }
            var lowerBound = 4
            switch response {
                case .declinedSharing:
                    print("User declined to share age.")
                    return false
               case .sharing(let range):
                    lowerBound = range.lowerBound ?? 4
                    print("User age range: \(range.lowerBound ?? 0)-\(range.upperBound ?? 99)")
                @unknown default:
                    print( "fatalError()")
                    return false
            }
            
            var ok = false
            if lowerBound >= 18 { // Not needed ?
                // Allow access to 18+ features.
                ok = true
            } else if lowerBound >= 15 { // Not needed ?
                // Allow access to 15+ features.
                ok = true
            } else if lowerBound >= 13 { // Not needed ?
                // Require parental consent ?
                // Allow access to 13+ features.
                ok = true // if consent OK
            } else  {
                // Require parental consent ?
                // Show age-appropriate content
                ok = true // if consent OK
            }
            return ok // Authorized for all 4+

        } catch { // AgeRangeService.Error.notAvailable {
           // No age range provided.
           return false
        }
    }
    
    func executeStart() {
        welcomeLabel.isHidden = false
    }
    
    @IBAction func start(_ sender: UIButton) {
        Task { @MainActor in
            
            if #available(iOS 26.0, *) {
                if await testAgeRange() {
                    // Need to test for parental control here ?
                } else {
                    // Alert and exit the app ?
                }
                
            } else {
                // do nothing ? Can we run the app ?
            }
            executeStart()
        }
    }
Where to find sample code for SB2420 compliance and questions
 
 
Q