rust_macios/user_notifications/
un_notification_category.rs1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5 foundation::{NSArray, NSString},
6 object,
7 objective_c_runtime::{
8 nil,
9 traits::{FromId, PNSObject},
10 },
11};
12
13use super::un_notification_action::UNNotificationAction;
14
15object! {
16 unsafe pub struct UNNotificationCategory;
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
21#[repr(u64)]
22pub enum UNNotificationCategoryOptions {
23 None = 0,
24 CustomDismissAction = (1 << 0),
25 AllowInCarPlay = (1 << 1),
26 HiddenPreviewsShowTitle = (1 << 2),
27 HiddenPreviewsShowSubtitle = (1 << 3),
28 #[deprecated]
29 AllowAnnouncement = (1 << 4),
30}
31
32#[interface_impl(NSObject)]
33impl UNNotificationCategory {
34 #[method]
39 pub fn category_with_identifier_actions_intent_identifiers_options(
40 identifier: NSString,
41 actions: NSArray<UNNotificationAction>,
42 intent_identifiers: NSArray<NSString>,
43 options: &[UNNotificationCategoryOptions],
44 ) -> Self
45 where
46 Self: Sized + FromId,
47 {
48 let options = options
49 .iter()
50 .fold(0u64, |init, option| init | *option as u64);
51
52 unsafe {
53 Self::from_id(
54 msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers options: options],
55 )
56 }
57 }
58
59 #[method]
61 pub fn category_with_identifier_actions_intent_identifiers_hidden_previews_body_placeholder_options(
62 identifier: NSString,
63 actions: NSArray<UNNotificationAction>,
64 intent_identifiers: NSArray<NSString>,
65 hidden_previews_body_placeholder: Option<NSString>,
66 options: &[UNNotificationCategoryOptions],
67 ) -> Self
68 where
69 Self: Sized + FromId,
70 {
71 let hidden_previews_body_placeholder = match hidden_previews_body_placeholder {
72 Some(value) => value.m_self(),
73 None => nil,
74 };
75
76 let options = options
77 .iter()
78 .fold(0u64, |init, option| init | *option as u64);
79
80 unsafe {
81 Self::from_id(
82 msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers hiddenPreviewsBodyPlaceholder: hidden_previews_body_placeholder options: options],
83 )
84 }
85 }
86
87 pub fn categoryWithIdentifier_actions_intentIdentifiers_hiddenPreviewsBodyPlaceholder_categorySummaryFormat_options(
88 identifier: NSString,
89 actions: NSArray<UNNotificationAction>,
90 intent_identifiers: NSArray<NSString>,
91 hidden_previews_body_placeholder: NSString,
92 category_summary_format: NSString,
93 options: &[UNNotificationCategoryOptions],
94 ) -> Self
95 where
96 Self: Sized + FromId,
97 {
98 let options = options
99 .iter()
100 .fold(0u64, |init, option| init | *option as u64);
101
102 unsafe {
103 Self::from_id(
104 msg_send![Self::m_class(), categoryWithIdentifier: identifier actions: actions intentIdentifiers: intent_identifiers hiddenPreviewsBodyPlaceholder: hidden_previews_body_placeholder categorySummaryFormat: categorySummaryFormat options: options],
105 )
106 }
107 }
108
109 #[property]
114 pub fn identifier(&self) -> NSString {
115 unsafe { NSString::from_id(msg_send![self.m_self(), identifier]) }
116 }
117
118 #[property]
120 pub fn actions(&self) -> NSArray<UNNotificationAction> {
121 unsafe { NSArray::from_id(msg_send![self.m_self(), actions]) }
122 }
123
124 #[property]
126 pub fn intent_identifiers(&self) -> NSArray<NSString> {
127 unsafe { NSArray::from_id(msg_send![self.m_self(), intentIdentifiers]) }
128 }
129
130 #[property]
132 pub fn hidden_previews_body_placeholder(&self) -> NSString {
133 unsafe { NSString::from_id(msg_send![self.m_self(), hiddenPreviewsBodyPlaceholder]) }
134 }
135
136 #[property]
138 pub fn category_summary_format(&self) -> NSString {
139 unsafe { NSString::from_id(msg_send![self.m_self(), categorySummaryFormat]) }
140 }
141
142 #[property]
144 pub fn options(&self) -> UNNotificationCategoryOptions {
145 unsafe { msg_send![self.m_self(), options] }
146 }
147}