use objc::{msg_send, sel, sel_impl};
use rust_macios_objective_c_runtime_proc_macros::interface_impl;
use crate::{
foundation::{NSDictionary, NSError, NSString, NSURL},
object,
objective_c_runtime::{
id,
traits::{FromId, PNSObject},
},
};
object! {
unsafe pub struct UNNotificationAttachment;
}
extern "C" {
pub static UNNotificationAttachmentOptionsTypeHintKey: NSString;
pub static UNNotificationAttachmentOptionsThumbnailHiddenKey: NSString;
pub static UNNotificationAttachmentOptionsThumbnailClippingRectKey: NSString;
pub static UNNotificationAttachmentOptionsThumbnailTimeKey: NSString;
}
#[interface_impl(NSObject)]
impl UNNotificationAttachment {
#[method]
pub fn attachment_with_identifier_url_options(
identifier: NSString,
url: NSURL,
options: NSDictionary<id, id>,
) -> Result<Self, NSError>
where
Self: Sized + FromId,
{
unsafe {
let mut error = NSError::m_alloc();
let ptr = Self::from_id(msg_send![
Self::m_class(),
attachmentWithIdentifier: identifier
URL: url
options: options
error: &mut error
]);
if error.m_self().is_null() {
Ok(ptr)
} else {
Err(error)
}
}
}
#[property]
pub fn identifier(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
}
#[property]
pub fn url(&self) -> NSURL {
unsafe { NSURL::from_id(msg_send![self.m_self(), URL]) }
}
#[property]
pub fn _type(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), type]) }
}
}