rust_macios/user_notifications/
un_notification_content.rs1use libc::c_double;
2use objc::{msg_send, sel, sel_impl};
3use rust_macios_objective_c_runtime_proc_macros::interface_impl;
4
5use crate::{
6 foundation::{NSArray, NSDictionary, NSError, NSNumber, NSString, UInt},
7 object,
8 objective_c_runtime::{
9 id,
10 traits::{FromId, PNSObject},
11 },
12 utils::to_optional,
13};
14
15use super::{UNNotificationAttachment, UNNotificationSound};
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
18#[repr(i64)]
19pub enum UNNotificationInterruptionLevel {
20 Passive,
21 Active,
22 TimeSensitive,
23 Critical,
24}
25
26object! {
27 unsafe pub struct UNNotificationContent;
29}
30
31#[interface_impl(NSObject)]
32impl UNNotificationContent {
33 #[property]
35 pub fn title(&self) -> NSString {
36 unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
37 }
38
39 #[property]
41 pub fn subtitle(&self) -> NSString {
42 unsafe { NSString::from_id(msg_send![self.m_self(), subtitle]) }
43 }
44
45 #[property]
47 pub fn body(&self) -> NSString {
48 unsafe { NSString::from_id(msg_send![self.m_self(), body]) }
49 }
50
51 #[property]
56 pub fn attachments(&self) -> NSArray<UNNotificationAttachment> {
57 unsafe { NSArray::from_id(msg_send![self.m_self(), attachments]) }
58 }
59
60 #[property]
62 pub fn user_info(&self) -> NSDictionary<id, id> {
63 unsafe { NSDictionary::from_id(msg_send![self.m_self(), userInfo]) }
64 }
65
66 #[property]
71 pub fn launch_image_name(&self) -> NSString {
72 unsafe { NSString::from_id(msg_send![self.m_self(), launchImageName]) }
73 }
74
75 #[property]
77 pub fn badge(&self) -> Option<NSNumber> {
78 unsafe { to_optional(msg_send![self.m_self(), badge]) }
79 }
80
81 #[property]
83 pub fn target_content_identifier(&self) -> Option<NSString> {
84 unsafe { to_optional(msg_send![self.m_self(), targetContentIdentifier]) }
85 }
86
87 #[property]
92 pub fn sound(&self) -> Option<UNNotificationSound> {
93 unsafe { to_optional(msg_send![self.m_self(), sound]) }
94 }
95
96 #[property]
98 pub fn interruption_level(&self) -> UNNotificationInterruptionLevel {
99 unsafe { msg_send![self.m_self(), interruptionLevel] }
100 }
101
102 #[property]
104 pub fn relevance_score(&self) -> c_double {
105 unsafe { msg_send![self.m_self(), relevanceScore] }
106 }
107
108 #[property]
110 pub fn filter_criteria(&self) -> Option<NSString> {
111 unsafe { to_optional(msg_send![self.m_self(), filterCriteria]) }
112 }
113
114 #[property]
119 pub fn thread_identifier(&self) -> NSString {
120 unsafe { NSString::from_id(msg_send![self.m_self(), threadIdentifier]) }
121 }
122
123 #[property]
125 pub fn category_identifier(&self) -> NSString {
126 unsafe { NSString::from_id(msg_send![self.m_self(), categoryIdentifier]) }
127 }
128
129 #[property]
131 pub fn summary_argument(&self) -> NSString {
132 unsafe { NSString::from_id(msg_send![self.m_self(), summaryArgument]) }
133 }
134
135 #[property]
137 pub fn summary_argument_count(&self) -> UInt {
138 unsafe { msg_send![self.m_self(), summaryArgumentCount] }
139 }
140
141 #[method]
146 pub fn content_by_updating_with_provider(
147 &mut self,
148 provider: id,
149 ) -> Result<UNNotificationContent, NSError> {
150 unsafe {
151 let mut error = NSError::m_alloc();
152
153 let ptr = UNNotificationContent::from_id(
154 msg_send![self.m_self(), contentByUpdatingWithProvider: provider error: &mut error],
155 );
156
157 if error.m_self().is_null() {
158 Ok(ptr)
159 } else {
160 Err(error)
161 }
162 }
163 }
164}