rust_macios/background_tasks/
bg_processing_task_request.rs

1use 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_bool,
11};
12
13use super::IBGTaskRequest;
14
15object! {
16    /// A request to launch your app in the background to execute a processing task that can take minutes to complete.
17    unsafe pub struct BGProcessingTaskRequest;
18}
19
20#[interface_impl(BGTaskRequest)]
21impl BGProcessingTaskRequest {
22    /* Initializing a Processing Task Request
23     */
24
25    /// Return a new processing task request for the specified identifier.
26    #[method]
27    pub fn init_with_identifier(&mut self, identifier: NSString) -> Self
28    where
29        Self: Sized + FromId,
30    {
31        unsafe { Self::from_id(msg_send![self.m_self(), initWithIdentifier: identifier]) }
32    }
33
34    /* Setting Task Request Options
35     */
36
37    /// A Boolean specifying if the processing task requires a device connected to power.
38    #[property]
39    pub fn requires_external_power() -> bool {
40        unsafe { to_bool(msg_send![Self::m_class(), requiresExternalPower]) }
41    }
42
43    /// A Boolean specifying if the processing task requires network connectivity.
44    #[property]
45    pub fn requires_network_connectivity() -> bool {
46        unsafe { to_bool(msg_send![Self::m_class(), requiresNetworkConnectivity]) }
47    }
48}
49
50impl IBGTaskRequest for BGProcessingTaskRequest {}
51
52impl Default for BGProcessingTaskRequest {
53    fn default() -> Self {
54        Self::m_new()
55    }
56}