rust_macios/user_notifications/
un_notification_attachment.rs1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5 foundation::{NSDictionary, NSError, NSString, NSURL},
6 object,
7 objective_c_runtime::{
8 id,
9 traits::{FromId, PNSObject},
10 },
11};
12
13object! {
14 unsafe pub struct UNNotificationAttachment;
16}
17
18extern "C" {
19 pub static UNNotificationAttachmentOptionsTypeHintKey: NSString;
21
22 pub static UNNotificationAttachmentOptionsThumbnailHiddenKey: NSString;
24
25 pub static UNNotificationAttachmentOptionsThumbnailClippingRectKey: NSString;
27
28 pub static UNNotificationAttachmentOptionsThumbnailTimeKey: NSString;
30}
31
32#[interface_impl(NSObject)]
33impl UNNotificationAttachment {
34 #[method]
39 pub fn attachment_with_identifier_url_options(
40 identifier: NSString,
41 url: NSURL,
42 options: NSDictionary<id, id>,
43 ) -> Result<Self, NSError>
44 where
45 Self: Sized + FromId,
46 {
47 unsafe {
48 let mut error = NSError::m_alloc();
49 let ptr = Self::from_id(msg_send![
50 Self::m_class(),
51 attachmentWithIdentifier: identifier
52 URL: url
53 options: options
54 error: &mut error
55 ]);
56
57 if error.m_self().is_null() {
58 Ok(ptr)
59 } else {
60 Err(error)
61 }
62 }
63 }
64
65 #[property]
70 pub fn identifier(&self) -> NSString {
71 unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
72 }
73
74 #[property]
76 pub fn url(&self) -> NSURL {
77 unsafe { NSURL::from_id(msg_send![self.m_self(), URL]) }
78 }
79
80 #[property]
82 pub fn _type(&self) -> NSString {
83 unsafe { NSString::from_id(msg_send![self.m_self(), type]) }
84 }
85}