Privacy Management
1 Privacy Permission Check
1.1 Interface Prototype
See Host Privacy Policy Access for details
func setPrivacyChecker(checker: TJPrivacyCheckerListener?)
2 Host Privacy Policy Access
2.1 Function Introduction
To standardize the behavior of developers when invoking system capabilities, such as camera, Bluetooth, sensors, etc., the host provides an asynchronous call interface for permission checking to third-party access platforms. Third-party platforms can check or guide users to grant relevant permissions through this interface.
2.2 Access Instructions
1. Implement the `TJPrivacyCheckerListener` interface, where the possible values of `methodName` are shown in the next section Related APIs section.
public protocol TJPrivacyCheckerListener {
/// Requests permissions for system capabilities, such as camera, Bluetooth, sensors, etc.
/// - Parameters:
/// - methodName: The name of the method requiring permission validation
/// - callback: Callback with the validation result
func requirePrivacy(methodName: String, callback: @escaping TJRequirePrivacyCallback)
}
-
TJPrivacyCheckerListenercallbackTJRequirePrivacyCallbackandTJPrivacyResultare defined as follows, parameters:-
methodNameis the passedmethodName; -
passedindicates whether the inspection has passed; -
errorNoanderrorMessagewill be returned to the relevant call in the js.
-
public typealias TJRequirePrivacyCallback = (String, TJPrivacyResult) -> Void
public class TJPrivacyResult {
public init(passed: Bool, errNo: Int, errMsg: String) {
self.passed = passed
errorNo = errNo
errorMessage = errMsg
}
func isPassed() -> Bool {
passed
}
func getErrorNo() -> Int {
errorNo
}
func getErrorMessage() -> String {
errorMessage
}
private var passed: Bool
private var errorNo: Int
private var errorMessage: String
}
- Pass in a custom
PrivacyCheckerviaRuntimeGameHandle.
let gameHandle: RuntimeGameHandle
gameHandle.setPrivacyChecker(new RandomPrivacyChecker())
3 Related APIs
| Information Type | methodName | Description |
|---|---|---|
| Microphone | startRecorderManager | RecorderManager.start |
| Camera | startCameraManager | tj.createCamera |
| Bluetooth | openBluetoothAdapter, createBLEPeripheralServer | tj.openBluetoothAdapter, tj.createBLEPeripheralServer |
| Gyroscope Sensor | startGyroscope | tj.startGyroscope |
| Direction Sensor | startDeviceMotionListening | tj.startDeviceMotionListening |
| Magnetic Field Sensor | startCompass | tj.startCompass |
| Acceleration Sensor | startAccelerometer | tj.startAccelerometer |
4 Example
A PrivacyChecker that returns random results.
class RandomPrivacyChecker: TJPrivacyCheckerListener {
private func randomResult() -> PrivacyResult {
let random = Int.random(in: 0...9)
if random < 5 {
return PrivacyResult(granted: true, errorCode: 0, errorMessage: "privacy granted")
} else {
return PrivacyResult(granted: false, errorCode: 1, errorMessage: "privacy denied")
}
}
func requirePrivacy(methodName: String, callback: TJRequirePrivacyCallback?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let callback = callback {
let result = self.randomResult()
print("requirePrivacy: \(methodName) \(result.errorMessage)")
callback.onPrivacyResult(methodName, result)
}
}
}
}