objc2_link_presentation/generated/
LPLinkMetadata.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    /// An object that contains metadata about a URL.
12    ///
13    /// Use ``LPLinkMetadata`` to store the metadata about a URL, including its
14    /// title, icon, images and video.
15    ///
16    /// Fetch metadata using ``LPMetadataProvider``. For remote URLs, cache the
17    /// metadata locally to avoid the data and performance cost of fetching it from
18    /// the internet every time you present it. ``LPLinkMetadata`` is serializable
19    /// with
20    /// <doc
21    /// ://com.apple.documentation/documentation/foundation/nssecurecoding>.
22    ///
23    /// For local file URLs, the
24    /// <doc
25    /// ://com.apple.documentation/documentation/quicklookthumbnailing> API
26    /// retrieves a representative thumbnail for the file, if possible.
27    ///
28    /// ## Provide custom metadata
29    ///
30    /// Say your app already has a database of links, with titles and images that
31    /// weren’t fetched by ``LPMetadataProvider``. You don’t have to fetch new
32    /// metadata from the internet in order to accelerate the share sheet or to
33    /// present a rich link. Instead, you can fill in the fields of
34    /// ``LPLinkMetadata`` yourself.
35    ///
36    /// Create an ``LPLinkMetadata`` object, and fill in at least the
37    /// ``LPLinkMetadata/originalURL`` and ``LPLinkMetadata/URL`` fields, plus
38    /// whatever additional information you have.
39    ///
40    /// ```swift
41    /// func activityViewControllerLinkMetadata(_: UIActivityViewController) -> LPLinkMetadata? {
42    /// let metadata = LPLinkMetadata()
43    /// metadata.originalURL = URL(string: "https://www.example.com/apple-pie")
44    /// metadata.url = metadata.originalURL
45    /// metadata.title = "The Greatest Apple Pie In The World"
46    /// metadata.imageProvider = NSItemProvider.init(contentsOf:
47    /// Bundle.main.url(forResource: "apple-pie", withExtension: "jpg"))
48    /// return metadata
49    /// }
50    /// ```
51    ///
52    /// ## Accelerate the share sheet preview
53    ///
54    /// For existing apps that share URLs, the share sheet automatically presents a
55    /// preview of the link. The preview first shows a placeholder link icon
56    /// alongside the base URL while fetching the link’s metadata over the network.
57    /// The preview updates once the link’s icon and title become available.
58    ///
59    /// If you already have an ``LPLinkMetadata`` object for a URL, pass it to the
60    /// share sheet to present the preview instantly, without fetching data over the
61    /// network. In your implementation of
62    /// <doc
63    /// ://com.apple.documentation/documentation/uikit/uiactivityitemsource/3144571-activityviewcontrollerlinkmetada>,
64    /// return the metadata object.
65    ///
66    /// ```swift
67    /// func activityViewControllerLinkMetadata(_:
68    /// UIActivityViewController) -> LPLinkMetadata? {
69    /// return self.metadata
70    /// }
71    /// ```
72    ///
73    /// If the user chooses to share to Messages, the same metadata passes directly
74    /// through, providing a smooth and seamless experience with no unnecessary
75    /// loading.
76    ///
77    /// See also [Apple's documentation](https://developer.apple.com/documentation/linkpresentation/lplinkmetadata?language=objc)
78    #[unsafe(super(NSObject))]
79    #[derive(Debug, PartialEq, Eq, Hash)]
80    pub struct LPLinkMetadata;
81);
82
83extern_conformance!(
84    unsafe impl NSCoding for LPLinkMetadata {}
85);
86
87extern_conformance!(
88    unsafe impl NSCopying for LPLinkMetadata {}
89);
90
91unsafe impl CopyingHelper for LPLinkMetadata {
92    type Result = Self;
93}
94
95extern_conformance!(
96    unsafe impl NSObjectProtocol for LPLinkMetadata {}
97);
98
99extern_conformance!(
100    unsafe impl NSSecureCoding for LPLinkMetadata {}
101);
102
103impl LPLinkMetadata {
104    extern_methods!(
105        /// The original URL of the metadata request.
106        #[unsafe(method(originalURL))]
107        #[unsafe(method_family = none)]
108        pub unsafe fn originalURL(&self) -> Option<Retained<NSURL>>;
109
110        /// Setter for [`originalURL`][Self::originalURL].
111        #[unsafe(method(setOriginalURL:))]
112        #[unsafe(method_family = none)]
113        pub unsafe fn setOriginalURL(&self, original_url: Option<&NSURL>);
114
115        /// The URL that returned the metadata, taking server-side redirects into
116        /// account.
117        ///
118        /// The URL that returns the metadata may differ from the
119        /// ``LPLinkMetadata/originalURL`` to which you sent the metadata request. This
120        /// can happen if the server redirects the request, for example, when a resource
121        /// has moved, or when the original URL is a domain alias.
122        #[unsafe(method(URL))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
125
126        /// Setter for [`URL`][Self::URL].
127        #[unsafe(method(setURL:))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn setURL(&self, url: Option<&NSURL>);
130
131        /// A representative title for the URL.
132        #[unsafe(method(title))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn title(&self) -> Option<Retained<NSString>>;
135
136        /// Setter for [`title`][Self::title].
137        ///
138        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
139        #[unsafe(method(setTitle:))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn setTitle(&self, title: Option<&NSString>);
142
143        /// An object that retrieves data corresponding to a representative icon for the
144        /// URL.
145        #[unsafe(method(iconProvider))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn iconProvider(&self) -> Option<Retained<NSItemProvider>>;
148
149        /// Setter for [`iconProvider`][Self::iconProvider].
150        #[unsafe(method(setIconProvider:))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn setIconProvider(&self, icon_provider: Option<&NSItemProvider>);
153
154        /// An object that retrieves data corresponding to a representative image for
155        /// the URL.
156        #[unsafe(method(imageProvider))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn imageProvider(&self) -> Option<Retained<NSItemProvider>>;
159
160        /// Setter for [`imageProvider`][Self::imageProvider].
161        #[unsafe(method(setImageProvider:))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn setImageProvider(&self, image_provider: Option<&NSItemProvider>);
164
165        /// An object that retrieves data corresponding to a representative video for
166        /// the URL.
167        ///
168        /// The item provider returns a video that
169        /// <doc
170        /// ://com.apple.documentation/documentation/avfoundation> can play.
171        #[unsafe(method(videoProvider))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn videoProvider(&self) -> Option<Retained<NSItemProvider>>;
174
175        /// Setter for [`videoProvider`][Self::videoProvider].
176        #[unsafe(method(setVideoProvider:))]
177        #[unsafe(method_family = none)]
178        pub unsafe fn setVideoProvider(&self, video_provider: Option<&NSItemProvider>);
179
180        /// A remote URL corresponding to a representative video for the URL.
181        ///
182        /// This may reference a remote video file that
183        /// <doc
184        /// ://com.apple.documentation/documentation/avfoundation> can stream,
185        /// or a YouTube video URL.
186        #[unsafe(method(remoteVideoURL))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn remoteVideoURL(&self) -> Option<Retained<NSURL>>;
189
190        /// Setter for [`remoteVideoURL`][Self::remoteVideoURL].
191        #[unsafe(method(setRemoteVideoURL:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn setRemoteVideoURL(&self, remote_video_url: Option<&NSURL>);
194    );
195}
196
197/// Methods declared on superclass `NSObject`.
198impl LPLinkMetadata {
199    extern_methods!(
200        #[unsafe(method(init))]
201        #[unsafe(method_family = init)]
202        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
203
204        #[unsafe(method(new))]
205        #[unsafe(method_family = new)]
206        pub unsafe fn new() -> Retained<Self>;
207    );
208}