I'm trying to work with the beta version of the Declared Age Range framework based on an article's tutorial but am getting the following error:
[C:1-3] Error received: Invalidated by remote connection.
and AgeRangeService.Error.notAvailable
is being thrown on the call to requestAgeRange
. I'm using Xcode 26 beta 5 and my simulator is running the 26.0 beta. The iCloud account that I have signed into the simulator has a DOB set as well.
This is my full ContentView where I'm trying to accomplish this.
struct ContentView: View {
@Environment(\.requestAgeRange) var requestAgeRange
@State var advancedFeaturesEnabled = false
var body: some View {
VStack {
Button("Advanced Features") {}
.disabled(!advancedFeaturesEnabled)
}
.task {
await requestAgeRangeHelper()
}
}
func requestAgeRangeHelper() async {
do {
let ageRangeResponse = try await requestAgeRange(ageGates: 16)
switch ageRangeResponse {
case let .sharing(range):
if let lowerBound = range.lowerBound, lowerBound >= 16 {
advancedFeaturesEnabled = true
}
case .declinedSharing:
break
// Handle declined sharing
default:
break
}
} catch AgeRangeService.Error.invalidRequest {
print("Invalid request")
// Handle invalid request (e.g., age range < 2 years)
} catch AgeRangeService.Error.notAvailable {
print("Not available")
// Handle device configuration issues
} catch {
print("Other")
}
}
}