rust_macios/user_notifications/
un_notification_request.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    foundation::NSString,
5    object,
6    objective_c_runtime::{
7        macros::interface_impl,
8        traits::{FromId, PNSObject},
9    },
10    utils::to_optional,
11};
12
13use super::{UNNotificationContent, UNNotificationTrigger};
14
15object! {
16    /// A request to schedule a local notification, which includes the content of the notification and the trigger conditions for delivery.
17    unsafe pub struct UNNotificationRequest;
18}
19
20#[interface_impl(NSObject)]
21impl UNNotificationRequest {
22    /* Creating a Notification Request
23     */
24
25    /// Creates a notification request object that you use to schedule a notification.
26    #[method]
27    pub fn request_with_identifier_content_trigger(
28        identifier: &NSString,
29        content: &UNNotificationContent,
30        trigger: &UNNotificationTrigger,
31    ) -> Self
32    where
33        Self: Sized + FromId,
34    {
35        unsafe {
36            Self::from_id(
37                msg_send![Self::m_class(),  requestWithIdentifier: identifier.m_self() content: content.m_self() trigger: trigger.m_self()],
38            )
39        }
40    }
41
42    /* Getting the Request Details
43     */
44
45    /// The unique identifier for this notification request.
46    #[property]
47    pub fn identifier(&self) -> NSString {
48        unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
49    }
50
51    /// The content associated with the notification.
52    #[property]
53    pub fn content(&self) -> UNNotificationContent {
54        unsafe { UNNotificationContent::from_id(msg_send![self.m_self(), content]) }
55    }
56
57    /// The conditions that trigger the delivery of the notification.
58    #[property]
59    pub fn trigger(&self) -> Option<UNNotificationTrigger> {
60        unsafe { to_optional(msg_send![self.m_self(), trigger]) }
61    }
62}