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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! 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 contains metadata about a URL.
///
/// Use ``LPLinkMetadata`` to store the metadata about a URL, including its
/// title, icon, images and video.
///
/// Fetch metadata using ``LPMetadataProvider``. For remote URLs, cache the
/// metadata locally to avoid the data and performance cost of fetching it from
/// the internet every time you present it. ``LPLinkMetadata`` is serializable
/// with
/// <doc
/// ://com.apple.documentation/documentation/foundation/nssecurecoding>.
///
/// For local file URLs, the
/// <doc
/// ://com.apple.documentation/documentation/quicklookthumbnailing> API
/// retrieves a representative thumbnail for the file, if possible.
///
/// ## Provide custom metadata
///
/// Say your app already has a database of links, with titles and images that
/// weren’t fetched by ``LPMetadataProvider``. You don’t have to fetch new
/// metadata from the internet in order to accelerate the share sheet or to
/// present a rich link. Instead, you can fill in the fields of
/// ``LPLinkMetadata`` yourself.
///
/// Create an ``LPLinkMetadata`` object, and fill in at least the
/// ``LPLinkMetadata/originalURL`` and ``LPLinkMetadata/URL`` fields, plus
/// whatever additional information you have.
///
/// ```swift
/// func activityViewControllerLinkMetadata(_: UIActivityViewController) -> LPLinkMetadata? {
/// let metadata = LPLinkMetadata()
/// metadata.originalURL = URL(string: "https://www.example.com/apple-pie")
/// metadata.url = metadata.originalURL
/// metadata.title = "The Greatest Apple Pie In The World"
/// metadata.imageProvider = NSItemProvider.init(contentsOf:
/// Bundle.main.url(forResource: "apple-pie", withExtension: "jpg"))
/// return metadata
/// }
/// ```
///
/// ## Accelerate the share sheet preview
///
/// For existing apps that share URLs, the share sheet automatically presents a
/// preview of the link. The preview first shows a placeholder link icon
/// alongside the base URL while fetching the link’s metadata over the network.
/// The preview updates once the link’s icon and title become available.
///
/// If you already have an ``LPLinkMetadata`` object for a URL, pass it to the
/// share sheet to present the preview instantly, without fetching data over the
/// network. In your implementation of
/// <doc
/// ://com.apple.documentation/documentation/uikit/uiactivityitemsource/3144571-activityviewcontrollerlinkmetada>,
/// return the metadata object.
///
/// ```swift
/// func activityViewControllerLinkMetadata(_:
/// UIActivityViewController) -> LPLinkMetadata? {
/// return self.metadata
/// }
/// ```
///
/// If the user chooses to share to Messages, the same metadata passes directly
/// through, providing a smooth and seamless experience with no unnecessary
/// loading.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/linkpresentation/lplinkmetadata?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct LPLinkMetadata;
);
extern_conformance!(
unsafe impl NSCoding for LPLinkMetadata {}
);
extern_conformance!(
unsafe impl NSCopying for LPLinkMetadata {}
);
unsafe impl CopyingHelper for LPLinkMetadata {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for LPLinkMetadata {}
);
extern_conformance!(
unsafe impl NSSecureCoding for LPLinkMetadata {}
);
impl LPLinkMetadata {
extern_methods!(
/// The original URL of the metadata request.
#[unsafe(method(originalURL))]
#[unsafe(method_family = none)]
pub unsafe fn originalURL(&self) -> Option<Retained<NSURL>>;
/// Setter for [`originalURL`][Self::originalURL].
#[unsafe(method(setOriginalURL:))]
#[unsafe(method_family = none)]
pub unsafe fn setOriginalURL(&self, original_url: Option<&NSURL>);
/// The URL that returned the metadata, taking server-side redirects into
/// account.
///
/// The URL that returns the metadata may differ from the
/// ``LPLinkMetadata/originalURL`` to which you sent the metadata request. This
/// can happen if the server redirects the request, for example, when a resource
/// has moved, or when the original URL is a domain alias.
#[unsafe(method(URL))]
#[unsafe(method_family = none)]
pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
/// Setter for [`URL`][Self::URL].
#[unsafe(method(setURL:))]
#[unsafe(method_family = none)]
pub unsafe fn setURL(&self, url: Option<&NSURL>);
/// A representative title for the URL.
#[unsafe(method(title))]
#[unsafe(method_family = none)]
pub unsafe fn title(&self) -> Option<Retained<NSString>>;
/// Setter for [`title`][Self::title].
///
/// This is [copied][objc2_foundation::NSCopying::copy] when set.
#[unsafe(method(setTitle:))]
#[unsafe(method_family = none)]
pub unsafe fn setTitle(&self, title: Option<&NSString>);
/// An object that retrieves data corresponding to a representative icon for the
/// URL.
#[unsafe(method(iconProvider))]
#[unsafe(method_family = none)]
pub unsafe fn iconProvider(&self) -> Option<Retained<NSItemProvider>>;
/// Setter for [`iconProvider`][Self::iconProvider].
#[unsafe(method(setIconProvider:))]
#[unsafe(method_family = none)]
pub unsafe fn setIconProvider(&self, icon_provider: Option<&NSItemProvider>);
/// An object that retrieves data corresponding to a representative image for
/// the URL.
#[unsafe(method(imageProvider))]
#[unsafe(method_family = none)]
pub unsafe fn imageProvider(&self) -> Option<Retained<NSItemProvider>>;
/// Setter for [`imageProvider`][Self::imageProvider].
#[unsafe(method(setImageProvider:))]
#[unsafe(method_family = none)]
pub unsafe fn setImageProvider(&self, image_provider: Option<&NSItemProvider>);
/// An object that retrieves data corresponding to a representative video for
/// the URL.
///
/// The item provider returns a video that
/// <doc
/// ://com.apple.documentation/documentation/avfoundation> can play.
#[unsafe(method(videoProvider))]
#[unsafe(method_family = none)]
pub unsafe fn videoProvider(&self) -> Option<Retained<NSItemProvider>>;
/// Setter for [`videoProvider`][Self::videoProvider].
#[unsafe(method(setVideoProvider:))]
#[unsafe(method_family = none)]
pub unsafe fn setVideoProvider(&self, video_provider: Option<&NSItemProvider>);
/// A remote URL corresponding to a representative video for the URL.
///
/// This may reference a remote video file that
/// <doc
/// ://com.apple.documentation/documentation/avfoundation> can stream,
/// or a YouTube video URL.
#[unsafe(method(remoteVideoURL))]
#[unsafe(method_family = none)]
pub unsafe fn remoteVideoURL(&self) -> Option<Retained<NSURL>>;
/// Setter for [`remoteVideoURL`][Self::remoteVideoURL].
#[unsafe(method(setRemoteVideoURL:))]
#[unsafe(method_family = none)]
pub unsafe fn setRemoteVideoURL(&self, remote_video_url: Option<&NSURL>);
);
}
/// Methods declared on superclass `NSObject`.
impl LPLinkMetadata {
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>;
);
}