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
53unsafe impl NSObjectProtocol for DCDevice {}
54
55impl DCDevice {
56    extern_methods!(
57        /// A representation of the device for which you want to query the two bits of
58        /// data.
59        #[unsafe(method(currentDevice))]
60        #[unsafe(method_family = none)]
61        pub unsafe fn currentDevice() -> Retained<DCDevice>;
62
63        /// A Boolean value that indicates whether the device supports the DeviceCheck
64        /// API.
65        #[unsafe(method(isSupported))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn isSupported(&self) -> bool;
68
69        #[cfg(feature = "block2")]
70        /// Generates a token that identifies the current device.
71        ///
72        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
73        /// > as shown on this page, or you can call it as an asynchronous method that has the
74        /// > following declaration:
75        /// >
76        /// >  ```swift
77        /// > func generateToken() async throws -> Data
78        /// > ```
79        /// >  For example:
80        /// >  ```swift
81        /// > let token = try await generateToken()
82        /// > ```
83        /// >  For information about concurrency and asynchronous code in Swift, see
84        /// <doc
85        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
86        ///
87        /// Your server uses the generated token in its requests to get or set the
88        /// persistent bits for the current device. You should treat the token you
89        /// receive in the completion block as single-use. Although the token remains
90        /// valid long enough for your server to retry a specific request if necessary,
91        /// you should not use a token multiple times. Instead, use this method to
92        /// generate a new token.
93        ///
94        /// - Note: The app you use to generate the token must be associated with your
95        /// developer account; otherwise, the generation request fails.
96        ///
97        /// - Parameters:
98        /// - completion: A completion block that includes the following parameters:
99        /// - `token`:  An ephemeral token that identifies the current device.
100        /// - `error`: The error that occurred, if any.
101        #[unsafe(method(generateTokenWithCompletionHandler:))]
102        #[unsafe(method_family = none)]
103        pub unsafe fn generateTokenWithCompletionHandler(
104            &self,
105            completion: &block2::Block<dyn Fn(*mut NSData, *mut NSError)>,
106        );
107    );
108}
109
110/// Methods declared on superclass `NSObject`.
111impl DCDevice {
112    extern_methods!(
113        #[unsafe(method(init))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
116
117        #[unsafe(method(new))]
118        #[unsafe(method_family = new)]
119        pub unsafe fn new() -> Retained<Self>;
120    );
121}