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