objc2_background_tasks/generated/
BGTaskScheduler.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern "C" {
11    /// The background tasks error domain as a string.
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtaskschedulererrordomain?language=objc)
14    pub static BGTaskSchedulerErrorDomain: &'static NSErrorDomain;
15}
16
17/// An enumeration of the task scheduling errors.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtaskschedulererrorcode?language=objc)
20// NS_ERROR_ENUM
21#[repr(transparent)]
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
23pub struct BGTaskSchedulerErrorCode(pub NSInteger);
24impl BGTaskSchedulerErrorCode {
25    /// A task scheduling error indicating that the app or extension can’t
26    /// schedule background work.
27    ///
28    /// This error usually occurs for one of following reasons:
29    ///
30    /// - The user has disabled background refresh in settings.
31    /// - The app is running on Simulator which doesn’t support background processing.
32    /// - The keyboard extension either hasn’t set
33    /// <doc
34    /// ://com.apple.documentation/documentation/bundleresources/information_property_list/nsextension/nsextensionattributes/requestsopenaccess>
35    /// to `YES` in [The Info.plist
36    /// File](https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/ProvidingUserAssitAppleHelp/authoring_help/authoring_help_book.html#//apple_ref/doc/uid/TP30000903-CH206-SW22),
37    /// or the user hasn’t granted open access.
38    /// - The extension type isn’t able to schedule background tasks.
39    #[doc(alias = "BGTaskSchedulerErrorCodeUnavailable")]
40    pub const Unavailable: Self = Self(1);
41    /// A task scheduling error indicating that there are too many pending tasks
42    /// of the type requested.
43    ///
44    /// Try canceling some existing task requests and then resubmit the request
45    /// that failed.
46    #[doc(alias = "BGTaskSchedulerErrorCodeTooManyPendingTaskRequests")]
47    pub const TooManyPendingTaskRequests: Self = Self(2);
48    /// A task scheduling error indicating the app isn’t permitted to schedule the
49    /// task.
50    ///
51    /// There are two causes for this error:
52    ///
53    /// - The app doesn’t set the appropriate mode in the
54    /// <doc
55    /// ://com.apple.documentation/documentation/bundleresources/information_property_list/uibackgroundmodes>
56    /// array.
57    ///
58    /// - The task identifier of the submitted task wasn’t in the
59    /// <doc
60    /// ://com.apple.documentation/documentation/bundleresources/information_property_list/bgtaskschedulerpermittedidentifiers>
61    /// array in [the Info.plist
62    /// File](https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/ProvidingUserAssitAppleHelp/authoring_help/authoring_help_book.html#//apple_ref/doc/uid/TP30000903-CH206-SW22).
63    #[doc(alias = "BGTaskSchedulerErrorCodeNotPermitted")]
64    pub const NotPermitted: Self = Self(3);
65}
66
67unsafe impl Encode for BGTaskSchedulerErrorCode {
68    const ENCODING: Encoding = NSInteger::ENCODING;
69}
70
71unsafe impl RefEncode for BGTaskSchedulerErrorCode {
72    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
73}
74
75extern_class!(
76    /// A class for scheduling task requests that launch your app in the background.
77    ///
78    /// Background tasks give your app a way to run code while the app is suspended.
79    /// To learn how to register, schedule, and run a background task, see
80    /// <doc
81    /// ://com.apple.documentation/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app>.
82    ///
83    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler?language=objc)
84    #[unsafe(super(NSObject))]
85    #[derive(Debug, PartialEq, Eq, Hash)]
86    pub struct BGTaskScheduler;
87);
88
89unsafe impl NSObjectProtocol for BGTaskScheduler {}
90
91impl BGTaskScheduler {
92    extern_methods!(
93        #[unsafe(method(init))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
96
97        #[unsafe(method(new))]
98        #[unsafe(method_family = new)]
99        pub unsafe fn new() -> Retained<Self>;
100
101        /// The shared background task scheduler instance.
102        #[unsafe(method(sharedScheduler))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn sharedScheduler() -> Retained<BGTaskScheduler>;
105
106        #[cfg(feature = "BGTaskRequest")]
107        /// Submit a previously registered background task for execution.
108        ///
109        /// Submitting a task request for an unexecuted task that’s already in the queue
110        /// replaces the previous task request.
111        ///
112        /// There can be a total of 1 refresh task and 10 processing tasks scheduled at
113        /// any time. Trying to schedule more tasks returns
114        /// ``BGTaskSchedulerErrorCode/BGTaskSchedulerErrorCodeTooManyPendingTaskRequests``.
115        ///
116        /// - Parameters:
117        /// - taskRequest: A background task request object specifying the task
118        /// - error: On input, a pointer to an error object. If an error occurs, this pointer is set to an error object containing the error information. Specify `nil` for this parameter to ignore the error information.
119        /// identifier and optional configuration information.
120        #[unsafe(method(submitTaskRequest:error:_))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn submitTaskRequest_error(
123            &self,
124            task_request: &BGTaskRequest,
125        ) -> Result<(), Retained<NSError>>;
126
127        /// Cancel a previously scheduled task request.
128        ///
129        /// - Parameters:
130        /// - identifier: The string identifier of the task request to cancel.
131        #[unsafe(method(cancelTaskRequestWithIdentifier:))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn cancelTaskRequestWithIdentifier(&self, identifier: &NSString);
134
135        /// Cancel all scheduled task requests.
136        #[unsafe(method(cancelAllTaskRequests))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn cancelAllTaskRequests(&self);
139
140        #[cfg(all(feature = "BGTaskRequest", feature = "block2"))]
141        /// Request a list of unexecuted scheduled task requests.
142        ///
143        /// - Parameters:
144        /// - completionHandler: The completion handler called with the pending tasks.
145        /// The handler may execute on a background thread.
146        ///
147        /// The handler takes a single parameter `tasksRequests`, an array of `BGTaskRequest`
148        /// objects. The array is empty if there are no scheduled tasks.
149        ///
150        /// The objects passed in the array are copies of the existing requests. Changing the
151        /// attributes of a request has no effect. To change the attributes submit a new
152        /// task request using ``BGTaskScheduler/submitTaskRequest:error:``.
153        #[unsafe(method(getPendingTaskRequestsWithCompletionHandler:))]
154        #[unsafe(method_family = none)]
155        pub unsafe fn getPendingTaskRequestsWithCompletionHandler(
156            &self,
157            completion_handler: &block2::Block<dyn Fn(NonNull<NSArray<BGTaskRequest>>)>,
158        );
159    );
160}