objc2_device_check/generated/
DCDevice.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// A representation of a device that provides a unique, authenticated token.
12    ///
13    /// Use the shared instance of the `DCDevice` class to generate a
14    /// token that identifies a device. Call the
15    /// ``DeviceCheck/DCDevice/generateTokenWithCompletionHandler:`` method to get
16    /// the token, and then send it to your server:
17    ///
18    /// ```swift
19    /// if DCDevice.current.isSupported { // Always test for availability.
20    /// DCDevice.current.generateToken { token, error in
21    /// guard error == nil else { /* Handle the error. */ }
22    ///
23    /// // Send the token to your server.
24    /// }
25    /// }
26    /// ```
27    ///
28    /// On your server, combine the token with an authentication key that you obtain
29    /// from Apple, and use the result to request access to two per-device binary
30    /// digits (bits). After authenticating the device, Apple passes the current
31    /// values of the bits, along with the date they were last modified, to your
32    /// server. Your server applies its business logic to this information and
33    /// communicates the results to your app. For more information about server-side
34    /// procedures, see
35    /// <doc
36    /// :accessing-and-modifying-per-device-data>.
37    ///
38    /// - Note: To use the `DCDevice` class, your app must have an app
39    /// ID that you register on the [Apple
40    /// Developer](https://developer.apple.com/account/) website.
41    ///
42    /// Apple records the bits for you, and reports the bits back to you, but you’re
43    /// responsible for keeping track of what the bits mean. You’re also responsible
44    /// for determining when to reset the bits for a given device; for example, when
45    /// a user sells the device to someone else.
46    ///
47    /// See also [Apple's documentation](https://developer.apple.com/documentation/devicecheck/dcdevice?language=objc)
48    #[unsafe(super(NSObject))]
49    #[derive(Debug, PartialEq, Eq, Hash)]
50    pub struct DCDevice;
51);
52
53extern_conformance!(
54    unsafe impl NSObjectProtocol for DCDevice {}
55);
56
57impl DCDevice {
58    extern_methods!(
59        /// A representation of the device for which you want to query the two bits of
60        /// data.
61        #[unsafe(method(currentDevice))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn currentDevice() -> Retained<DCDevice>;
64
65        /// A Boolean value that indicates whether the device supports the DeviceCheck
66        /// API.
67        #[unsafe(method(isSupported))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn isSupported(&self) -> bool;
70
71        #[cfg(feature = "block2")]
72        /// Generates a token that identifies the current device.
73        ///
74        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
75        /// > as shown on this page, or you can call it as an asynchronous method that has the
76        /// > following declaration:
77        /// >
78        /// >  ```swift
79        /// > func generateToken() async throws -> Data
80        /// > ```
81        /// >  For example:
82        /// >  ```swift
83        /// > let token = try await generateToken()
84        /// > ```
85        /// >  For information about concurrency and asynchronous code in Swift, see
86        /// <doc
87        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
88        ///
89        /// Your server uses the generated token in its requests to get or set the
90        /// persistent bits for the current device. You should treat the token you
91        /// receive in the completion block as single-use. Although the token remains
92        /// valid long enough for your server to retry a specific request if necessary,
93        /// you should not use a token multiple times. Instead, use this method to
94        /// generate a new token.
95        ///
96        /// - Note: The app you use to generate the token must be associated with your
97        /// developer account; otherwise, the generation request fails.
98        ///
99        /// - Parameters:
100        /// - completion: A completion block that includes the following parameters:
101        /// - `token`:  An ephemeral token that identifies the current device.
102        /// - `error`: The error that occurred, if any.
103        #[unsafe(method(generateTokenWithCompletionHandler:))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn generateTokenWithCompletionHandler(
106            &self,
107            completion: &block2::DynBlock<dyn Fn(*mut NSData, *mut NSError)>,
108        );
109    );
110}
111
112/// Methods declared on superclass `NSObject`.
113impl DCDevice {
114    extern_methods!(
115        #[unsafe(method(init))]
116        #[unsafe(method_family = init)]
117        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
118
119        #[unsafe(method(new))]
120        #[unsafe(method_family = new)]
121        pub unsafe fn new() -> Retained<Self>;
122    );
123}