@globules-io/cordova-plugin-apple-age-check 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -53
- package/package.json +3 -3
- package/plugin.xml +9 -2
- package/src/ios/AgeCheckPlugin.swift +254 -59
- package/www/AgeCheck.js +87 -60
package/README.md
CHANGED
|
@@ -1,53 +1,142 @@
|
|
|
1
|
-
# cordova-plugin-apple-age-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
# cordova-plugin-apple-age-check
|
|
2
|
+
|
|
3
|
+
Cordova plugin for Apple's Declared Age Range API on iOS.
|
|
4
|
+
|
|
5
|
+
https://developer.apple.com/documentation/declaredagerange
|
|
6
|
+
|
|
7
|
+
`checkAge()` calls `AgeRangeService.requestAgeRange(ageGates:in:)`. The system sheet asks the person, or a parent in a Family Sharing group, to share an age band. The band is cut at the age gates you pass.
|
|
8
|
+
|
|
9
|
+
Build with the iOS 26.5 SDK or later so the `confirmed` declaration is included. The call runs on iOS 26 and later. `isEligibleForAgeFeatures()` needs iOS 26.2.
|
|
10
|
+
|
|
11
|
+
The plugin adds the `com.apple.developer.declared-age-range` entitlement and weakly links `DeclaredAgeRange`. The app's App ID still needs the Declared Age Range capability in its provisioning profile.
|
|
12
|
+
|
|
13
|
+
### Add the plugin
|
|
14
|
+
|
|
15
|
+
> cordova plugin add @globules-io/cordova-plugin-apple-age-check
|
|
16
|
+
|
|
17
|
+
### Remove the plugin
|
|
18
|
+
|
|
19
|
+
> cordova plugin rm @globules-io/cordova-plugin-apple-age-check
|
|
20
|
+
|
|
21
|
+
### Usage
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
AgeCheckPlugin.checkAge([13, 16, 18],
|
|
25
|
+
function(result) {
|
|
26
|
+
if (result.sharingStatus !== 'SHARING') {
|
|
27
|
+
// The person declined. In some regulated regions the system shares anyway.
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ageLower is null below the lowest gate.
|
|
32
|
+
// ageUpper is null at or above the highest gate.
|
|
33
|
+
console.log(result.ageLower, result.ageUpper, result.ageRangeDeclaration);
|
|
34
|
+
},
|
|
35
|
+
function(error) {
|
|
36
|
+
console.error(error.code, error.message);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
AgeCheckPlugin.isSupported(function(supported) {
|
|
41
|
+
console.log(supported);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
AgeCheckPlugin.isEligibleForAgeFeatures(function(eligible) {
|
|
45
|
+
console.log(eligible);
|
|
46
|
+
}, function(error) {
|
|
47
|
+
console.error(error.code, error.message);
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`checkAge(success, error)` uses a single gate of 18. `checkAge(16, success, error)` uses that one gate.
|
|
52
|
+
|
|
53
|
+
Pass 1 to 3 gates. Each later gate must be at least 2 years above the one before it.
|
|
54
|
+
|
|
55
|
+
## Response
|
|
56
|
+
|
|
57
|
+
`checkAge` resolves when the person shares or declines. It rejects when the request fails.
|
|
58
|
+
|
|
59
|
+
| Field | Values |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `sharingStatus` | `SHARING`, `DECLINED` |
|
|
62
|
+
| `ageLower` | Inclusive lower bound, or `null` when the person is below the lowest gate |
|
|
63
|
+
| `ageUpper` | Inclusive upper bound, or `null` when the person is at or above the highest gate |
|
|
64
|
+
| `ageRangeDeclaration` | How the band was set, or `null` |
|
|
65
|
+
| `activeParentalControls` | Array of control names. Empty when none are shared |
|
|
66
|
+
|
|
67
|
+
`ageLower`, `ageUpper`, and `ageRangeDeclaration` are `null` when `sharingStatus` is `DECLINED`.
|
|
68
|
+
|
|
69
|
+
### ageRangeDeclaration
|
|
70
|
+
|
|
71
|
+
#### SELF_DECLARED
|
|
72
|
+
|
|
73
|
+
The person set the band on their Apple Account.
|
|
74
|
+
|
|
75
|
+
#### GUARDIAN_DECLARED
|
|
76
|
+
|
|
77
|
+
A parent, guardian, or Family Organizer set the band.
|
|
78
|
+
|
|
79
|
+
#### CONFIRMED
|
|
80
|
+
|
|
81
|
+
The band was confirmed. On iOS 26.5 and later this replaces the method-specific values below.
|
|
82
|
+
|
|
83
|
+
#### PAYMENT_CHECKED
|
|
84
|
+
|
|
85
|
+
The person confirmed with a payment method. Not returned on iOS 26.5 and later.
|
|
86
|
+
|
|
87
|
+
#### GOVERNMENT_ID_CHECKED
|
|
88
|
+
|
|
89
|
+
The person confirmed with a government ID. Not returned on iOS 26.5 and later.
|
|
90
|
+
|
|
91
|
+
#### CHECKED_BY_OTHER_METHOD
|
|
92
|
+
|
|
93
|
+
The person confirmed with another method. Not returned on iOS 26.5 and later.
|
|
94
|
+
|
|
95
|
+
#### GUARDIAN_PAYMENT_CHECKED
|
|
96
|
+
|
|
97
|
+
A parent or guardian confirmed with a payment method.
|
|
98
|
+
|
|
99
|
+
#### GUARDIAN_GOVERNMENT_ID_CHECKED
|
|
100
|
+
|
|
101
|
+
A parent or guardian confirmed with a government ID.
|
|
102
|
+
|
|
103
|
+
#### GUARDIAN_CHECKED_BY_OTHER_METHOD
|
|
104
|
+
|
|
105
|
+
A parent or guardian confirmed with another method.
|
|
106
|
+
|
|
107
|
+
### activeParentalControls
|
|
108
|
+
|
|
109
|
+
#### COMMUNICATION_LIMITS
|
|
110
|
+
|
|
111
|
+
Screen Time communication limits are on.
|
|
112
|
+
|
|
113
|
+
#### SIGNIFICANT_APP_CHANGE_APPROVAL_REQUIRED
|
|
114
|
+
|
|
115
|
+
An older signal that a significant app change needs parental approval. Prefer `isEligibleForAgeFeatures()` and Apple's significant-update APIs for that flow. This plugin does not present the significant-update sheet.
|
|
116
|
+
|
|
117
|
+
## Error object
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
{
|
|
121
|
+
"code": "NOT_AVAILABLE",
|
|
122
|
+
"message": "..."
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Code | Meaning |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| `NOT_AVAILABLE` | The system could not share an age range. |
|
|
129
|
+
| `INVALID_REQUEST` | The gates or the request configuration were rejected. |
|
|
130
|
+
| `DECLINED_ONBOARDING` | The person declined age-range onboarding. |
|
|
131
|
+
| `INVALID_ACCOUNT` | This Apple Account cannot share an age range. |
|
|
132
|
+
| `NETWORK` | A network or server failure. |
|
|
133
|
+
| `INVALID_AGE_GATES` | The gates were missing, out of range, or less than 2 years apart. |
|
|
134
|
+
| `NO_VIEW_CONTROLLER` | There is no Cordova view controller to present the sheet. |
|
|
135
|
+
| `UNSUPPORTED` | This iOS version does not have the called API. |
|
|
136
|
+
| `UNKNOWN` | Any other failure. |
|
|
137
|
+
|
|
138
|
+
## Eligibility
|
|
139
|
+
|
|
140
|
+
`isSupported()` is true on iOS 26 and later. It does not ask the person anything.
|
|
141
|
+
|
|
142
|
+
`isEligibleForAgeFeatures()` is true when this person is in a region that requires age assurance. It needs iOS 26.2. On macOS, Apple returns false. A regulated region can share the band without a decline option.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globules-io/cordova-plugin-apple-age-check",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "iOS Age Check using Apple's Declared Age Range API",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "@globules-io/cordova-plugin-apple-age-check",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/globules-io/cordova-plugin-apple-age-check.git"
|
|
21
|
+
"url": "git+https://github.com/globules-io/cordova-plugin-apple-age-check.git"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"cordova": ">=10.0.0"
|
|
25
25
|
}
|
|
26
|
-
}
|
|
26
|
+
}
|
package/plugin.xml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
3
|
id="@globules-io/cordova-plugin-apple-age-check"
|
|
4
|
-
version="0.
|
|
4
|
+
version="0.2.0">
|
|
5
5
|
<name>Apple Age Check</name>
|
|
6
|
-
<description>iOS implementation for Apple's Declared Age Range API (iOS 26+)
|
|
6
|
+
<description>iOS implementation for Apple's Declared Age Range API (iOS 26+).</description>
|
|
7
7
|
<license>MIT</license>
|
|
8
8
|
<keywords>cordova,ios,age,verification,declared,age-range</keywords>
|
|
9
9
|
<author email="info@globules.io">globules.io</author>
|
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
<engine name="cordova-ios" version=">=7.0.0" />
|
|
14
14
|
</engines>
|
|
15
15
|
<platform name="ios">
|
|
16
|
+
<framework src="DeclaredAgeRange.framework" weak="true" />
|
|
16
17
|
<source-file src="src/ios/AgeCheckPlugin.swift" />
|
|
18
|
+
<config-file target="Entitlements-Debug.plist" parent="com.apple.developer.declared-age-range">
|
|
19
|
+
<true />
|
|
20
|
+
</config-file>
|
|
21
|
+
<config-file target="Entitlements-Release.plist" parent="com.apple.developer.declared-age-range">
|
|
22
|
+
<true />
|
|
23
|
+
</config-file>
|
|
17
24
|
<config-file target="config.xml" parent="/widget">
|
|
18
25
|
<feature name="AgeCheck">
|
|
19
26
|
<param name="ios-package" value="AgeCheckPlugin" />
|
|
@@ -1,59 +1,254 @@
|
|
|
1
|
-
import Cordova
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
guard #available(iOS 26.0, *) else {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import Cordova
|
|
2
|
+
import UIKit
|
|
3
|
+
import DeclaredAgeRange
|
|
4
|
+
|
|
5
|
+
@objc(AgeCheckPlugin)
|
|
6
|
+
class AgeCheckPlugin: CDVPlugin {
|
|
7
|
+
|
|
8
|
+
@objc(checkAge:)
|
|
9
|
+
func checkAge(command: CDVInvokedUrlCommand) {
|
|
10
|
+
guard #available(iOS 26.0, *) else {
|
|
11
|
+
sendError(callbackId: command.callbackId, code: "UNSUPPORTED",
|
|
12
|
+
message: "Declared Age Range API requires iOS 26 or later")
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
guard let gates = ageGates(from: command) else {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let callbackId = command.callbackId ?? ""
|
|
21
|
+
Task { @MainActor in
|
|
22
|
+
guard let viewController = self.viewController else {
|
|
23
|
+
self.sendError(callbackId: callbackId, code: "NO_VIEW_CONTROLLER",
|
|
24
|
+
message: "Cordova view controller is null")
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
do {
|
|
29
|
+
let response = try await self.requestAgeRange(gates: gates, in: viewController)
|
|
30
|
+
let result = self.result(from: response)
|
|
31
|
+
let pluginResult = CDVPluginResult(status: .ok, messageAs: result)
|
|
32
|
+
self.commandDelegate.send(pluginResult, callbackId: callbackId)
|
|
33
|
+
} catch let error as AgeRangeService.Error {
|
|
34
|
+
self.sendError(callbackId: callbackId, code: self.errorCode(error),
|
|
35
|
+
message: error.localizedDescription)
|
|
36
|
+
} catch {
|
|
37
|
+
self.sendError(callbackId: callbackId, code: "UNKNOWN",
|
|
38
|
+
message: error.localizedDescription)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@objc(isSupported:)
|
|
44
|
+
func isSupported(command: CDVInvokedUrlCommand) {
|
|
45
|
+
let supported: Bool
|
|
46
|
+
if #available(iOS 26.0, *) {
|
|
47
|
+
supported = true
|
|
48
|
+
} else {
|
|
49
|
+
supported = false
|
|
50
|
+
}
|
|
51
|
+
let pluginResult = CDVPluginResult(status: .ok, messageAs: supported)
|
|
52
|
+
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// True when this person is in a region where age assurance applies. Requires iOS 26.2.
|
|
56
|
+
@objc(isEligibleForAgeFeatures:)
|
|
57
|
+
func isEligibleForAgeFeatures(command: CDVInvokedUrlCommand) {
|
|
58
|
+
guard #available(iOS 26.2, *) else {
|
|
59
|
+
sendError(callbackId: command.callbackId, code: "UNSUPPORTED",
|
|
60
|
+
message: "isEligibleForAgeFeatures requires iOS 26.2 or later")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let callbackId = command.callbackId ?? ""
|
|
65
|
+
Task { @MainActor in
|
|
66
|
+
do {
|
|
67
|
+
let eligible = try await AgeRangeService.shared.isEligibleForAgeFeatures
|
|
68
|
+
let pluginResult = CDVPluginResult(status: .ok, messageAs: eligible)
|
|
69
|
+
self.commandDelegate.send(pluginResult, callbackId: callbackId)
|
|
70
|
+
} catch let error as AgeRangeService.Error {
|
|
71
|
+
self.sendError(callbackId: callbackId, code: self.errorCode(error),
|
|
72
|
+
message: error.localizedDescription)
|
|
73
|
+
} catch {
|
|
74
|
+
self.sendError(callbackId: callbackId, code: "UNKNOWN",
|
|
75
|
+
message: error.localizedDescription)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@available(iOS 26.0, *)
|
|
81
|
+
private func requestAgeRange(gates: [Int], in viewController: UIViewController) async throws -> AgeRangeService.Response {
|
|
82
|
+
switch gates.count {
|
|
83
|
+
case 1:
|
|
84
|
+
return try await AgeRangeService.shared.requestAgeRange(ageGates: gates[0], in: viewController)
|
|
85
|
+
case 2:
|
|
86
|
+
return try await AgeRangeService.shared.requestAgeRange(ageGates: gates[0], gates[1], in: viewController)
|
|
87
|
+
default:
|
|
88
|
+
return try await AgeRangeService.shared.requestAgeRange(
|
|
89
|
+
ageGates: gates[0], gates[1], gates[2], in: viewController)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@available(iOS 26.0, *)
|
|
94
|
+
private func result(from response: AgeRangeService.Response) -> [String: Any] {
|
|
95
|
+
switch response {
|
|
96
|
+
case .sharing(let ageRange):
|
|
97
|
+
return [
|
|
98
|
+
"sharingStatus": "SHARING",
|
|
99
|
+
"ageLower": ageRange.lowerBound ?? NSNull(),
|
|
100
|
+
"ageUpper": ageRange.upperBound ?? NSNull(),
|
|
101
|
+
"ageRangeDeclaration": declarationName(ageRange.ageRangeDeclaration) ?? NSNull(),
|
|
102
|
+
"activeParentalControls": parentalControlNames(ageRange.activeParentalControls)
|
|
103
|
+
]
|
|
104
|
+
case .declinedSharing:
|
|
105
|
+
return [
|
|
106
|
+
"sharingStatus": "DECLINED",
|
|
107
|
+
"ageLower": NSNull(),
|
|
108
|
+
"ageUpper": NSNull(),
|
|
109
|
+
"ageRangeDeclaration": NSNull(),
|
|
110
|
+
"activeParentalControls": [String]()
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// `confirmed` is only in the iOS 26.5 SDK. The other branch stays exhaustive on earlier SDKs.
|
|
116
|
+
@available(iOS 26.0, *)
|
|
117
|
+
private func declarationName(_ declaration: AgeRangeService.AgeRangeDeclaration?) -> String? {
|
|
118
|
+
guard let declaration = declaration else {
|
|
119
|
+
return nil
|
|
120
|
+
}
|
|
121
|
+
if #available(iOS 26.5, *) {
|
|
122
|
+
switch declaration {
|
|
123
|
+
case .selfDeclared:
|
|
124
|
+
return "SELF_DECLARED"
|
|
125
|
+
case .guardianDeclared:
|
|
126
|
+
return "GUARDIAN_DECLARED"
|
|
127
|
+
case .confirmed:
|
|
128
|
+
return "CONFIRMED"
|
|
129
|
+
case .paymentChecked:
|
|
130
|
+
return "PAYMENT_CHECKED"
|
|
131
|
+
case .governmentIDChecked:
|
|
132
|
+
return "GOVERNMENT_ID_CHECKED"
|
|
133
|
+
case .checkedByOtherMethod:
|
|
134
|
+
return "CHECKED_BY_OTHER_METHOD"
|
|
135
|
+
case .guardianPaymentChecked:
|
|
136
|
+
return "GUARDIAN_PAYMENT_CHECKED"
|
|
137
|
+
case .guardianGovernmentIDChecked:
|
|
138
|
+
return "GUARDIAN_GOVERNMENT_ID_CHECKED"
|
|
139
|
+
case .guardianCheckedByOtherMethod:
|
|
140
|
+
return "GUARDIAN_CHECKED_BY_OTHER_METHOD"
|
|
141
|
+
@unknown default:
|
|
142
|
+
return "UNKNOWN"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
switch declaration {
|
|
146
|
+
case .selfDeclared:
|
|
147
|
+
return "SELF_DECLARED"
|
|
148
|
+
case .guardianDeclared:
|
|
149
|
+
return "GUARDIAN_DECLARED"
|
|
150
|
+
case .paymentChecked:
|
|
151
|
+
return "PAYMENT_CHECKED"
|
|
152
|
+
case .governmentIDChecked:
|
|
153
|
+
return "GOVERNMENT_ID_CHECKED"
|
|
154
|
+
case .checkedByOtherMethod:
|
|
155
|
+
return "CHECKED_BY_OTHER_METHOD"
|
|
156
|
+
case .guardianPaymentChecked:
|
|
157
|
+
return "GUARDIAN_PAYMENT_CHECKED"
|
|
158
|
+
case .guardianGovernmentIDChecked:
|
|
159
|
+
return "GUARDIAN_GOVERNMENT_ID_CHECKED"
|
|
160
|
+
case .guardianCheckedByOtherMethod:
|
|
161
|
+
return "GUARDIAN_CHECKED_BY_OTHER_METHOD"
|
|
162
|
+
@unknown default:
|
|
163
|
+
return "UNKNOWN"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@available(iOS 26.0, *)
|
|
168
|
+
private func parentalControlNames(_ controls: AgeRangeService.ParentalControls) -> [String] {
|
|
169
|
+
var names: [String] = []
|
|
170
|
+
if controls.contains(.communicationLimits) {
|
|
171
|
+
names.append("COMMUNICATION_LIMITS")
|
|
172
|
+
}
|
|
173
|
+
if controls.contains(.significantAppChangeApprovalRequired) {
|
|
174
|
+
names.append("SIGNIFICANT_APP_CHANGE_APPROVAL_REQUIRED")
|
|
175
|
+
}
|
|
176
|
+
return names
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@available(iOS 26.0, *)
|
|
180
|
+
private func errorCode(_ error: AgeRangeService.Error) -> String {
|
|
181
|
+
switch error {
|
|
182
|
+
case .notAvailable:
|
|
183
|
+
return "NOT_AVAILABLE"
|
|
184
|
+
case .invalidRequest:
|
|
185
|
+
return "INVALID_REQUEST"
|
|
186
|
+
case .declinedOnboarding:
|
|
187
|
+
return "DECLINED_ONBOARDING"
|
|
188
|
+
case .invalidAccount:
|
|
189
|
+
return "INVALID_ACCOUNT"
|
|
190
|
+
case .network:
|
|
191
|
+
return "NETWORK"
|
|
192
|
+
@unknown default:
|
|
193
|
+
return "UNKNOWN"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/// No argument keeps the previous single gate of 18. An argument is one gate or an array of up to three.
|
|
198
|
+
private func ageGates(from command: CDVInvokedUrlCommand) -> [Int]? {
|
|
199
|
+
let arguments = command.arguments ?? []
|
|
200
|
+
if arguments.isEmpty {
|
|
201
|
+
return [18]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let values: [Any]
|
|
205
|
+
if let list = arguments[0] as? [Any] {
|
|
206
|
+
values = list
|
|
207
|
+
} else if let list = arguments[0] as? NSArray {
|
|
208
|
+
values = list.compactMap { $0 }
|
|
209
|
+
} else {
|
|
210
|
+
values = arguments
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if values.isEmpty || values.count > 3 {
|
|
214
|
+
sendError(callbackId: command.callbackId, code: "INVALID_AGE_GATES",
|
|
215
|
+
message: "Pass 1 to 3 age gates. Each band must be at least 2 years wide.")
|
|
216
|
+
return nil
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var gates: [Int] = []
|
|
220
|
+
for value in values {
|
|
221
|
+
guard let gate = integer(from: value), gate >= 1 else {
|
|
222
|
+
sendError(callbackId: command.callbackId, code: "INVALID_AGE_GATES",
|
|
223
|
+
message: "Each age gate must be a whole number of 1 or more.")
|
|
224
|
+
return nil
|
|
225
|
+
}
|
|
226
|
+
gates.append(gate)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for index in 1..<gates.count where gates[index] - gates[index - 1] < 2 {
|
|
230
|
+
sendError(callbackId: command.callbackId, code: "INVALID_AGE_GATES",
|
|
231
|
+
message: "Age gates must increase, and each band must be at least 2 years wide.")
|
|
232
|
+
return nil
|
|
233
|
+
}
|
|
234
|
+
return gates
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private func integer(from value: Any) -> Int? {
|
|
238
|
+
guard let number = value as? NSNumber else {
|
|
239
|
+
return nil
|
|
240
|
+
}
|
|
241
|
+
if CFGetTypeID(number) == CFBooleanGetTypeID() {
|
|
242
|
+
return nil
|
|
243
|
+
}
|
|
244
|
+
return number.intValue
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private func sendError(callbackId: String?, code: String, message: String) {
|
|
248
|
+
let pluginResult = CDVPluginResult(status: .error, messageAs: [
|
|
249
|
+
"code": code,
|
|
250
|
+
"message": message
|
|
251
|
+
])
|
|
252
|
+
self.commandDelegate.send(pluginResult, callbackId: callbackId)
|
|
253
|
+
}
|
|
254
|
+
}
|
package/www/AgeCheck.js
CHANGED
|
@@ -1,60 +1,87 @@
|
|
|
1
|
-
var exec = require('cordova/exec');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* "
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
errorCallback
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
AgeCheckPlugin.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
var exec = require('cordova/exec');
|
|
2
|
+
|
|
3
|
+
var AgeCheckPlugin = {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ask the system to share an age range.
|
|
7
|
+
*
|
|
8
|
+
* Age gates are the thresholds that cut the range. Pass one number, or up to
|
|
9
|
+
* three numbers at least two years apart. Omitting them uses 18.
|
|
10
|
+
*
|
|
11
|
+
* A declined share is a successful result with sharingStatus "DECLINED".
|
|
12
|
+
*
|
|
13
|
+
* Result:
|
|
14
|
+
* {
|
|
15
|
+
* sharingStatus: "SHARING" | "DECLINED",
|
|
16
|
+
* ageLower: number | null,
|
|
17
|
+
* ageUpper: number | null,
|
|
18
|
+
* ageRangeDeclaration: "SELF_DECLARED" | "GUARDIAN_DECLARED" | "CONFIRMED" |
|
|
19
|
+
* "PAYMENT_CHECKED" | "GOVERNMENT_ID_CHECKED" | "CHECKED_BY_OTHER_METHOD" |
|
|
20
|
+
* "GUARDIAN_PAYMENT_CHECKED" | "GUARDIAN_GOVERNMENT_ID_CHECKED" |
|
|
21
|
+
* "GUARDIAN_CHECKED_BY_OTHER_METHOD" | "UNKNOWN" | null,
|
|
22
|
+
* activeParentalControls: string[]
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* ageLower is null when the person is below the lowest gate.
|
|
26
|
+
* ageUpper is null when the person is at or above the highest gate.
|
|
27
|
+
*/
|
|
28
|
+
AgeCheckPlugin.checkAge = function(ageGates, successCallback, errorCallback) {
|
|
29
|
+
if (typeof ageGates === 'function') {
|
|
30
|
+
errorCallback = successCallback;
|
|
31
|
+
successCallback = ageGates;
|
|
32
|
+
ageGates = [18];
|
|
33
|
+
} else if (typeof ageGates === 'number') {
|
|
34
|
+
ageGates = [ageGates];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof successCallback !== 'function') {
|
|
38
|
+
console.warn('AgeCheckPlugin.checkAge: successCallback must be a function');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (typeof errorCallback !== 'function') {
|
|
42
|
+
errorCallback = function(err) {
|
|
43
|
+
console.error('AgeCheckPlugin.checkAge error:', err);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(ageGates) || ageGates.length < 1 || ageGates.length > 3) {
|
|
47
|
+
errorCallback({
|
|
48
|
+
code: 'INVALID_AGE_GATES',
|
|
49
|
+
message: 'Pass 1 to 3 age gates.'
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exec(successCallback, errorCallback, 'AgeCheck', 'checkAge', [ageGates]);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* True when this device can call Declared Age Range (iOS 26 or later).
|
|
59
|
+
*/
|
|
60
|
+
AgeCheckPlugin.isSupported = function(successCallback, errorCallback) {
|
|
61
|
+
if (typeof successCallback !== 'function') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof errorCallback !== 'function') {
|
|
65
|
+
errorCallback = function() {};
|
|
66
|
+
}
|
|
67
|
+
exec(successCallback, errorCallback, 'AgeCheck', 'isSupported', []);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* True when this person is in a region that requires age assurance.
|
|
72
|
+
* Requires iOS 26.2. This does not ask the person to share an age range.
|
|
73
|
+
*/
|
|
74
|
+
AgeCheckPlugin.isEligibleForAgeFeatures = function(successCallback, errorCallback) {
|
|
75
|
+
if (typeof successCallback !== 'function') {
|
|
76
|
+
console.warn('AgeCheckPlugin.isEligibleForAgeFeatures: successCallback must be a function');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof errorCallback !== 'function') {
|
|
80
|
+
errorCallback = function(err) {
|
|
81
|
+
console.error('AgeCheckPlugin.isEligibleForAgeFeatures error:', err);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exec(successCallback, errorCallback, 'AgeCheck', 'isEligibleForAgeFeatures', []);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
module.exports = AgeCheckPlugin;
|