rust_macios/user_notifications/
un_notification_service_extension.rs

1use block::IntoConcreteBlock;
2use objc::{msg_send, sel, sel_impl};
3use rust_macios_objective_c_runtime_proc_macros::interface_impl;
4
5use crate::{object, objective_c_runtime::traits::PNSObject};
6
7use super::{UNNotificationContent, UNNotificationRequest};
8
9object! {
10    /// An object that modifies the content of a remote notification before it’s delivered to the user.
11    unsafe pub struct UNNotificationServiceExtension;
12}
13
14#[interface_impl(NSObject)]
15impl UNNotificationServiceExtension {
16    /// Asks you to make any needed changes to the notification and notify the system when you’re done.
17    #[method]
18    fn did_receive_notification_request_with_content_handler<F>(
19        &self,
20        request: UNNotificationRequest,
21        content_handler: F,
22    ) where
23        F: IntoConcreteBlock<(UNNotificationContent,)> + 'static,
24    {
25        unsafe {
26            let block = content_handler.into_concrete_block();
27            let block = block.copy();
28            msg_send![self.m_self(), didReceiveNotificationRequest: request withContentHandler: block]
29        }
30    }
31
32    /// Tells you that the system is terminating your extension.
33    #[method]
34    fn service_extension_time_will_expire(&self) {
35        unsafe { msg_send![self.m_self(), serviceExtensionTimeWillExpire] }
36    }
37}