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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//! 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!(
/// An object that retrieves metadata for a URL.
///
/// Use ``LPMetadataProvider`` to fetch metadata for a URL, including its title,
/// icon, and image or video links. All properties on the resulting
/// ``LPLinkMetadata`` instance are optional.
///
/// - Note: To enable macOS clients to fetch metadata for remote URLs, add the
/// <doc
/// ://com.apple.documentation/documentation/bundleresources/entitlements/com_apple_security_network_client>
/// entitlement.
///
/// ## Fetch link metadata from a URL
///
/// For each metadata request, create an instance of ``LPMetadataProvider`` and
/// call ``LPMetadataProvider/startFetchingMetadataForURL:completionHandler:``.
///
/// In the completion handler, check the error. If your user doesn’t have a
/// network connection, the fetch can fail. If the server doesn’t respond or is
/// too slow, the fetch can time out. Alternatively, the app may cancel the
/// request, or an unknown error may occur.
///
/// Otherwise, use the metadata however you want, for example, to populate the
/// title for a table view cell.
///
/// ```swift
/// let metadataProvider = LPMetadataProvider()
/// let url = URL(string: "https://www.apple.com/ipad")!
///
/// metadataProvider.startFetchingMetadata(for: url) { metadata, error in
/// if error != nil {
/// // The fetch failed; handle the error.
/// return
/// }
///
/// // Make use of fetched metadata.
/// }
/// ```
///
/// For more information about handling errors, see
/// ``LinkPresentation/LPError``.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/linkpresentation/lpmetadataprovider?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct LPMetadataProvider;
);
extern_conformance!(
unsafe impl NSObjectProtocol for LPMetadataProvider {}
);
impl LPMetadataProvider {
extern_methods!(
#[cfg(all(feature = "LPLinkMetadata", feature = "block2"))]
/// Fetches metadata for the given URL.
///
/// Call this method once per ``LPMetadataProvider`` instance. If you attempt to
/// fetch metadata multiple times on a single ``LPMetadataProvider`` instance,
/// it throws an error.
///
/// The completion handler executes on a background queue. Dispatch any
/// necessary UI updates back to the main queue. When the completion handler
/// returns, it deletes any file URLs returned in the resulting
/// ``LPLinkMetadata``.
///
/// > 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 startFetchingMetadata(for url: URL) async throws -> LPLinkMetadata
/// > ```
/// >
/// > For information about concurrency and asynchronous code in Swift, see
/// <doc
/// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
#[unsafe(method(startFetchingMetadataForURL:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn startFetchingMetadataForURL_completionHandler(
&self,
url: &NSURL,
completion_handler: &block2::DynBlock<dyn Fn(*mut LPLinkMetadata, *mut NSError)>,
);
#[cfg(all(feature = "LPLinkMetadata", feature = "block2"))]
/// Fetches metadata for the given ``NSURLRequest``.
///
/// Call this method once per ``LPMetadataProvider`` instance. If you attempt to
/// fetch metadata multiple times on a single ``LPMetadataProvider`` instance,
/// it throws an error.
///
/// The completion handler executes on a background queue. Dispatch any
/// necessary UI updates back to the main queue. When the completion handler
/// returns, it deletes any file URLs returned in the resulting
/// ``LPLinkMetadata``.
///
/// > 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 startFetchingMetadata(for request: URLRequest) async throws -> LPLinkMetadata
/// > ```
/// >
/// > For information about concurrency and asynchronous code in Swift, see
/// <doc
/// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
#[unsafe(method(startFetchingMetadataForRequest:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn startFetchingMetadataForRequest_completionHandler(
&self,
request: &NSURLRequest,
completion_handler: &block2::DynBlock<dyn Fn(*mut LPLinkMetadata, *mut NSError)>,
);
/// Cancels a metadata request.
///
/// This method invokes the completion handler with the error code
/// ``LPErrorCode/LPErrorMetadataFetchCancelled`` if the request hasn’t already
/// completed.
#[unsafe(method(cancel))]
#[unsafe(method_family = none)]
pub unsafe fn cancel(&self);
/// A Boolean value indicating whether to download subresources specified by the
/// metadata.
///
/// Subresources include the icon, image, or video. When set to `false`, the
/// returned ``LPLinkMetadata`` object consists only of metadata retrieved from
/// the main resource identified by the url passed to
/// ``LPMetadataProvider/startFetchingMetadataForURL:completionHandler:``.
///
/// The default value is `true`.
#[unsafe(method(shouldFetchSubresources))]
#[unsafe(method_family = none)]
pub unsafe fn shouldFetchSubresources(&self) -> bool;
/// Setter for [`shouldFetchSubresources`][Self::shouldFetchSubresources].
#[unsafe(method(setShouldFetchSubresources:))]
#[unsafe(method_family = none)]
pub unsafe fn setShouldFetchSubresources(&self, should_fetch_subresources: bool);
/// The time interval after which the request automatically fails if it hasn’t
/// already completed.
///
/// The default timeout interval is 30 seconds. If a metadata fetch takes longer
/// than the timeout interval, the completion handler is called with the error
/// code ``LPErrorCode/LPErrorMetadataFetchTimedOut``.
#[unsafe(method(timeout))]
#[unsafe(method_family = none)]
pub unsafe fn timeout(&self) -> NSTimeInterval;
/// Setter for [`timeout`][Self::timeout].
#[unsafe(method(setTimeout:))]
#[unsafe(method_family = none)]
pub unsafe fn setTimeout(&self, timeout: NSTimeInterval);
);
}
/// Methods declared on superclass `NSObject`.
impl LPMetadataProvider {
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>;
);
}