rust_macios/user_notifications/
un_notification_request.rs1use 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 unsafe pub struct UNNotificationRequest;
18}
19
20#[interface_impl(NSObject)]
21impl UNNotificationRequest {
22 #[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 #[property]
47 pub fn identifier(&self) -> NSString {
48 unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
49 }
50
51 #[property]
53 pub fn content(&self) -> UNNotificationContent {
54 unsafe { UNNotificationContent::from_id(msg_send![self.m_self(), content]) }
55 }
56
57 #[property]
59 pub fn trigger(&self) -> Option<UNNotificationTrigger> {
60 unsafe { to_optional(msg_send![self.m_self(), trigger]) }
61 }
62}