objc2-link-presentation 0.3.2

Bindings to the LinkPresentation framework
Documentation
//! 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>;
    );
}