objc2_exposure_notification/generated/ENManager.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// Overall status of Exposure Notification on the system.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/enstatus?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct ENStatus(pub NSInteger);
19impl ENStatus {
20 /// Status of Exposure Notification is unknown. This is the status before ENManager has activated successfully.
21 #[doc(alias = "ENStatusUnknown")]
22 pub const Unknown: Self = Self(0);
23 /// Exposure Notification is active on the system.
24 #[doc(alias = "ENStatusActive")]
25 pub const Active: Self = Self(1);
26 /// Exposure Notification is disabled. setExposureNotificationEnabled:completionHandler can be used to enable it.
27 #[doc(alias = "ENStatusDisabled")]
28 pub const Disabled: Self = Self(2);
29 /// Bluetooth has been turned off on the system. Bluetooth is required for Exposure Notification.
30 /// Note: this may not match the state of Bluetooth as reported by CoreBluetooth.
31 /// Exposure Notification is a system service and can use Bluetooth in situations when apps cannot.
32 /// So for the purposes of Exposure Notification, it's better to use this API instead of CoreBluetooth.
33 #[doc(alias = "ENStatusBluetoothOff")]
34 pub const BluetoothOff: Self = Self(3);
35 /// Exposure Notification is not active due to system restrictions, such as parental controls.
36 /// When in this state, the app cannot enable Exposure Notification.
37 #[doc(alias = "ENStatusRestricted")]
38 pub const Restricted: Self = Self(4);
39 /// For future use. Not returned by any APIs yet.
40 #[doc(alias = "ENStatusPaused")]
41 pub const Paused: Self = Self(5);
42 /// Exposure Notification is not available due to insufficient authorization.
43 #[doc(alias = "ENStatusUnauthorized")]
44 pub const Unauthorized: Self = Self(6);
45}
46
47unsafe impl Encode for ENStatus {
48 const ENCODING: Encoding = NSInteger::ENCODING;
49}
50
51unsafe impl RefEncode for ENStatus {
52 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
53}
54
55/// Activities that occurred while the app might not be running.
56///
57/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/enactivityflags?language=objc)
58// NS_OPTIONS
59#[repr(transparent)]
60#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
61pub struct ENActivityFlags(pub u32);
62bitflags::bitflags! {
63 impl ENActivityFlags: u32 {
64/// Reserved field
65 #[doc(alias = "ENActivityFlagsReserved1")]
66 const Reserved1 = 1<<0;
67/// Reserved field
68 #[doc(alias = "ENActivityFlagsReserved2")]
69 const Reserved2 = 1<<1;
70/// The app launched in the background to perform periodic operations on iOS 12.5.
71 #[doc(alias = "ENActivityFlagsPeriodicRun")]
72 const PeriodicRun = 1<<2;
73/// The app launched in the foreground to display information about the pre-authorized key release
74 #[doc(alias = "ENActivityFlagsPreAuthorizedKeyReleaseNotificationTapped")]
75 const PreAuthorizedKeyReleaseNotificationTapped = 1<<3;
76 }
77}
78
79unsafe impl Encode for ENActivityFlags {
80 const ENCODING: Encoding = u32::ENCODING;
81}
82
83unsafe impl RefEncode for ENActivityFlags {
84 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
85}
86
87/// Invoked after the app is launched to report activities that occurred while the app might not be running.
88///
89/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/enactivityhandler?language=objc)
90#[cfg(feature = "block2")]
91pub type ENActivityHandler = *mut block2::DynBlock<dyn Fn(ENActivityFlags)>;
92
93/// Invoked when getDiagnosisKeysWithCompletionHandler completes.
94/// If it completes successfully, keys will contain the Diagnosis Keys for this device and error will be nil.
95/// If it fails, keys will be nil and error indicates the reason it failed.
96///
97/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/engetdiagnosiskeyshandler?language=objc)
98#[cfg(all(feature = "ENCommon", feature = "block2"))]
99pub type ENGetDiagnosisKeysHandler =
100 *mut block2::DynBlock<dyn Fn(*mut NSArray<ENTemporaryExposureKey>, *mut NSError)>;
101
102/// Invoked when detecting exposures completes. It provides a summary of exposures.
103/// If it completes successfully, summary will contain a summary of exposures and error will be nil.
104/// If it fails, summary will be nil and error indicates the reason it failed.
105///
106/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/endetectexposureshandler?language=objc)
107#[cfg(all(feature = "ENCommon", feature = "block2"))]
108pub type ENDetectExposuresHandler =
109 *mut block2::DynBlock<dyn Fn(*mut ENExposureDetectionSummary, *mut NSError)>;
110
111/// [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/endiagnosiskeysavailablehandler?language=objc)
112#[cfg(all(feature = "ENCommon", feature = "block2"))]
113pub type ENDiagnosisKeysAvailableHandler =
114 *mut block2::DynBlock<dyn Fn(NonNull<NSArray<ENTemporaryExposureKey>>)>;
115
116/// Invoked when getting exposures completes. It provides info about each exposure.
117/// If it completes successfully, exposures will contain info about each exposure and error will be nil.
118/// If it fails, exposures will be nil and error indicates the reason it failed.
119///
120/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/engetexposureinfohandler?language=objc)
121#[cfg(all(feature = "ENCommon", feature = "block2"))]
122pub type ENGetExposureInfoHandler =
123 *mut block2::DynBlock<dyn Fn(*mut NSArray<ENExposureInfo>, *mut NSError)>;
124
125/// Invoked when getExposureWindows completes. It provides info about each exposure window.
126/// If it completes successfully, exposureWindows will non-nil and error will be nil.
127/// If it fails, exposureWindows will be nil and error indicates the reason it failed.
128///
129/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/engetexposurewindowshandler?language=objc)
130#[cfg(all(feature = "ENCommon", feature = "block2"))]
131pub type ENGetExposureWindowsHandler =
132 *mut block2::DynBlock<dyn Fn(*mut NSArray<ENExposureWindow>, *mut NSError)>;
133
134/// Invoked when getUserTraveled completes.
135///
136/// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/engetusertraveledhandler?language=objc)
137#[cfg(feature = "block2")]
138pub type ENGetUserTraveledHandler = *mut block2::DynBlock<dyn Fn(Bool, *mut NSError)>;
139
140extern_class!(
141 /// Manages Exposure Notification functionality.
142 ///
143 /// See also [Apple's documentation](https://developer.apple.com/documentation/exposurenotification/enmanager?language=objc)
144 #[unsafe(super(NSObject))]
145 #[derive(Debug, PartialEq, Eq, Hash)]
146 pub struct ENManager;
147);
148
149extern_conformance!(
150 unsafe impl NSObjectProtocol for ENManager {}
151);
152
153impl ENManager {
154 extern_methods!(
155 #[cfg(feature = "block2")]
156 /// Invoked when the app is launched for an activity while it might not be running.
157 /// When the app is launched, it should create an ENManager instance, set this handler, and then activate the manager.
158 #[unsafe(method(activityHandler))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn activityHandler(&self) -> ENActivityHandler;
161
162 #[cfg(feature = "block2")]
163 /// Setter for [`activityHandler`][Self::activityHandler].
164 #[unsafe(method(setActivityHandler:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn setActivityHandler(&self, activity_handler: ENActivityHandler);
167
168 #[cfg(feature = "dispatch2")]
169 #[unsafe(method(dispatchQueue))]
170 #[unsafe(method_family = none)]
171 pub unsafe fn dispatchQueue(&self) -> Retained<DispatchQueue>;
172
173 #[cfg(feature = "dispatch2")]
174 /// Setter for [`dispatchQueue`][Self::dispatchQueue].
175 #[unsafe(method(setDispatchQueue:))]
176 #[unsafe(method_family = none)]
177 pub unsafe fn setDispatchQueue(&self, dispatch_queue: &DispatchQueue);
178
179 /// Overall status of Exposure Notification. KVO may be used to monitor for changes.
180 #[unsafe(method(exposureNotificationStatus))]
181 #[unsafe(method_family = none)]
182 pub unsafe fn exposureNotificationStatus(&self) -> ENStatus;
183
184 #[cfg(feature = "dispatch2")]
185 /// Invoked exactly once when invalidation completes. This property is cleared before it's invoked to break retain cycles.
186 #[unsafe(method(invalidationHandler))]
187 #[unsafe(method_family = none)]
188 pub unsafe fn invalidationHandler(&self) -> dispatch_block_t;
189
190 #[cfg(feature = "dispatch2")]
191 /// Setter for [`invalidationHandler`][Self::invalidationHandler].
192 #[unsafe(method(setInvalidationHandler:))]
193 #[unsafe(method_family = none)]
194 pub unsafe fn setInvalidationHandler(&self, invalidation_handler: dispatch_block_t);
195
196 #[cfg(all(feature = "ENCommon", feature = "block2"))]
197 /// Activates the object to prepare it for use. Properties may not be usable until the completion handler reports success.
198 #[unsafe(method(activateWithCompletionHandler:))]
199 #[unsafe(method_family = none)]
200 pub unsafe fn activateWithCompletionHandler(&self, completion_handler: ENErrorHandler);
201
202 /// Stops any outstanding operations and invalidates this object. Once this is called, the object can no longer be used.
203 /// To start using ENManager again, a new instance of the class must be created and activated.
204 #[unsafe(method(invalidate))]
205 #[unsafe(method_family = none)]
206 pub unsafe fn invalidate(&self);
207
208 #[cfg(feature = "block2")]
209 /// Reports if the user traveled within an exposure period (e.g. 14 days).
210 #[unsafe(method(getUserTraveledWithCompletionHandler:))]
211 #[unsafe(method_family = none)]
212 pub unsafe fn getUserTraveledWithCompletionHandler(
213 &self,
214 completion_handler: ENGetUserTraveledHandler,
215 );
216
217 #[cfg(feature = "ENCommon")]
218 /// Reports the current authorization status of the app.
219 /// Apps can use this property to preflight authorization in order to determine if the user will be prompted.
220 #[unsafe(method(authorizationStatus))]
221 #[unsafe(method_family = none)]
222 pub unsafe fn authorizationStatus() -> ENAuthorizationStatus;
223
224 /// Indicates if Exposure Notification is enabled on the system. KVO may be used to monitor for changes.
225 /// This will be NO until activateWithCompletionHandler has completed successfully.
226 /// Note that even if it's enabled, it may be inactive for other reasons, such as Bluetooth being turned off.
227 /// The exposureNotificationStatus property can be monitored for the overall status of Exposure Notification.
228 #[unsafe(method(exposureNotificationEnabled))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn exposureNotificationEnabled(&self) -> bool;
231
232 #[cfg(all(feature = "ENCommon", feature = "block2"))]
233 /// Enables or disables Exposure Notification.
234 /// If not previously authorized, this shows a user dialog for consent to enable Exposure Notification.
235 /// Note: Disabling stops Bluetooth advertising and scanning related to Exposure Notification, but the
236 /// Diagnosis Keys and data will remain.
237 #[unsafe(method(setExposureNotificationEnabled:completionHandler:))]
238 #[unsafe(method_family = none)]
239 pub unsafe fn setExposureNotificationEnabled_completionHandler(
240 &self,
241 enabled: bool,
242 completion_handler: ENErrorHandler,
243 );
244
245 #[cfg(all(feature = "ENCommon", feature = "block2"))]
246 /// Detects exposures using the specified configuration to control the scoring algorithm.
247 /// This uses the diagnosis keys already known to the system.
248 /// Only available to apps with ENAPIVersion 2 or higher.
249 #[unsafe(method(detectExposuresWithConfiguration:completionHandler:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn detectExposuresWithConfiguration_completionHandler(
252 &self,
253 configuration: &ENExposureConfiguration,
254 completion_handler: ENDetectExposuresHandler,
255 ) -> Retained<NSProgress>;
256
257 #[cfg(all(feature = "ENCommon", feature = "block2"))]
258 /// Detects exposures using the specified configuration to control the scoring algorithm and URLs to specify the
259 /// files containing diagnosis keys the app has downloaded. The diagnosis key files must be signed appropriately.
260 /// When the app's ENAPIVersion is 2 or higher, keys already known to the system are included in the analysis.
261 #[unsafe(method(detectExposuresWithConfiguration:diagnosisKeyURLs:completionHandler:))]
262 #[unsafe(method_family = none)]
263 pub unsafe fn detectExposuresWithConfiguration_diagnosisKeyURLs_completionHandler(
264 &self,
265 configuration: &ENExposureConfiguration,
266 diagnosis_key_ur_ls: &NSArray<NSURL>,
267 completion_handler: ENDetectExposuresHandler,
268 ) -> Retained<NSProgress>;
269
270 #[cfg(all(feature = "ENCommon", feature = "block2"))]
271 /// Gets info about each exposure from the summary provided when exposure detection completes.
272 /// Using this API will inform the user that their exposure details have been revealed to the app.
273 /// The user explanation string will be displayed as part of the UI to inform the user of using this API.
274 #[deprecated = "Use getExposureWindowsFromSummary, if needed."]
275 #[unsafe(method(getExposureInfoFromSummary:userExplanation:completionHandler:))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn getExposureInfoFromSummary_userExplanation_completionHandler(
278 &self,
279 summary: &ENExposureDetectionSummary,
280 user_explanation: &NSString,
281 completion_handler: ENGetExposureInfoHandler,
282 ) -> Retained<NSProgress>;
283
284 #[cfg(all(feature = "ENCommon", feature = "block2"))]
285 /// Gets info about each exposure window from the summary provided when exposure detection completes.
286 #[unsafe(method(getExposureWindowsFromSummary:completionHandler:))]
287 #[unsafe(method_family = none)]
288 pub unsafe fn getExposureWindowsFromSummary_completionHandler(
289 &self,
290 summary: &ENExposureDetectionSummary,
291 completion_handler: ENGetExposureWindowsHandler,
292 ) -> Retained<NSProgress>;
293
294 #[cfg(all(feature = "ENCommon", feature = "block2"))]
295 /// Requests the temporary exposure keys used by this device to share with a server.
296 /// Each use of this API will present the user with system UI to authorize it.
297 #[unsafe(method(getDiagnosisKeysWithCompletionHandler:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn getDiagnosisKeysWithCompletionHandler(
300 &self,
301 completion_handler: ENGetDiagnosisKeysHandler,
302 );
303
304 #[cfg(all(feature = "ENCommon", feature = "block2"))]
305 /// Requests the temporary exposure keys, including the current key, used by this device for testing.
306 /// Each use of this API will present the user with system UI to authorize it.
307 /// WARNING: This API is only for use by developers. It requires a special entitlement that is not allowed in the app store.
308 /// It's only intended to allow developers to test without needing to wait 24 hours for a key to be released.
309 #[unsafe(method(getTestDiagnosisKeysWithCompletionHandler:))]
310 #[unsafe(method_family = none)]
311 pub unsafe fn getTestDiagnosisKeysWithCompletionHandler(
312 &self,
313 completion_handler: ENGetDiagnosisKeysHandler,
314 );
315
316 #[cfg(all(feature = "ENCommon", feature = "block2"))]
317 /// Invoked after requestPreAuthorizedDiagnosisKeys if user authorization is still valid.
318 #[unsafe(method(diagnosisKeysAvailableHandler))]
319 #[unsafe(method_family = none)]
320 pub unsafe fn diagnosisKeysAvailableHandler(&self) -> ENDiagnosisKeysAvailableHandler;
321
322 #[cfg(all(feature = "ENCommon", feature = "block2"))]
323 /// Setter for [`diagnosisKeysAvailableHandler`][Self::diagnosisKeysAvailableHandler].
324 #[unsafe(method(setDiagnosisKeysAvailableHandler:))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn setDiagnosisKeysAvailableHandler(
327 &self,
328 diagnosis_keys_available_handler: ENDiagnosisKeysAvailableHandler,
329 );
330
331 #[cfg(all(feature = "ENCommon", feature = "block2"))]
332 /// Authorizes a one-time, future release of diagnosis keys without a user prompt at the time of release.
333 /// This allows the user to authorize ahead of time in case they are unable to approve at the time of positive diagnosis.
334 /// WARNING: Application should be in foreground to request the authorization
335 #[unsafe(method(preAuthorizeDiagnosisKeysWithCompletionHandler:))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn preAuthorizeDiagnosisKeysWithCompletionHandler(
338 &self,
339 completion_handler: ENErrorHandler,
340 );
341
342 #[cfg(all(feature = "ENCommon", feature = "block2"))]
343 /// Requests diagnosis keys after previously using preAuthorizeDiagnosisKeys successfully.
344 /// This will display a notification to the user for the user to know the keys will be returned.
345 /// Keys are returned by invoking diagnosisKeysAvailable, which must be set before calling this.
346 #[unsafe(method(requestPreAuthorizedDiagnosisKeysWithCompletionHandler:))]
347 #[unsafe(method_family = none)]
348 pub unsafe fn requestPreAuthorizedDiagnosisKeysWithCompletionHandler(
349 &self,
350 completion_handler: ENErrorHandler,
351 );
352 );
353}
354
355/// Methods declared on superclass `NSObject`.
356impl ENManager {
357 extern_methods!(
358 #[unsafe(method(init))]
359 #[unsafe(method_family = init)]
360 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
361
362 #[unsafe(method(new))]
363 #[unsafe(method_family = new)]
364 pub unsafe fn new() -> Retained<Self>;
365 );
366}