rust_macios/user_notifications/
un_time_interval_notification_trigger.rs

1use objc::{msg_send, sel, sel_impl};
2use rust_macios_objective_c_runtime_proc_macros::interface_impl;
3
4use crate::{
5    foundation::{NSDate, NSTimeInterval},
6    object,
7    objective_c_runtime::traits::FromId,
8    utils::to_optional,
9};
10
11use super::IUNNotificationTrigger;
12
13object! {
14    /// A trigger condition that causes the system to deliver a notification after the amount of time you specify elapses.
15    unsafe pub struct UNTimeIntervalNotificationTrigger;
16}
17
18impl IUNNotificationTrigger for UNTimeIntervalNotificationTrigger {}
19
20#[interface_impl(UNNotificationTrigger)]
21impl UNTimeIntervalNotificationTrigger {
22    /* Creating a Time Interval Trigger
23     */
24
25    /// Creates a time interval trigger using the time value parameter.
26    #[method]
27    pub fn trigger_with_time_interval_repeats(time_interval: NSTimeInterval, repeats: bool) -> Self
28    where
29        Self: Sized + FromId,
30    {
31        unsafe {
32            Self::from_id(msg_send![
33                Self::m_class(),
34                triggerWithTimeInterval: time_interval
35                repeats: repeats
36            ])
37        }
38    }
39
40    /* Getting the Trigger Information
41     */
42
43    /// The next date at which the trigger conditions are met.
44    #[method]
45    pub fn next_trigger_date(&self) -> Option<NSDate> {
46        unsafe { to_optional(msg_send![self.m_self(), nextTriggerDate]) }
47    }
48
49    /// The time interval to create the trigger.
50    #[property]
51    pub fn time_interval(&self) -> NSTimeInterval {
52        unsafe { msg_send![self.m_self(), timeInterval] }
53    }
54}