objc2_background_tasks/generated/
BGTask.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_class!(
11    /// An abstract class representing a task that’s run while the app is in the
12    /// background.
13    ///
14    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtask?language=objc)
15    #[unsafe(super(NSObject))]
16    #[derive(Debug, PartialEq, Eq, Hash)]
17    pub struct BGTask;
18);
19
20extern_conformance!(
21    unsafe impl NSObjectProtocol for BGTask {}
22);
23
24impl BGTask {
25    extern_methods!(
26        /// The string identifier of the task.
27        ///
28        /// The identifier is the same as the one used to register the launch handler in
29        /// ``BGTaskScheduler/registerForTaskWithIdentifier:usingQueue:launchHandler:``.
30        #[unsafe(method(identifier))]
31        #[unsafe(method_family = none)]
32        pub unsafe fn identifier(&self) -> Retained<NSString>;
33
34        #[cfg(feature = "block2")]
35        /// A handler called shortly before the task’s background time expires.
36        ///
37        /// There is a limit to how long your app has to perform its background work, and your work may need to be interrupted
38        /// if system conditions change. Assign a handler to this property to cancel any ongoing tasks, perform any needed
39        /// cleanup, and then call setTaskCompletedWithSuccess: to signal completion to the system and allow your app to be
40        /// suspended. This property is cleared after it is called by the system or when ``BGTask/setTaskCompletedWithSuccess:``
41        /// is called. This is to mitigate the impact of a retain cycle created by referencing the BGTask instance inside this
42        /// block.
43        ///
44        /// The handler may be called before the background process uses the full amount of its allocated time.
45        ///
46        /// - Parameters:
47        /// - expirationHandler: The expiration handler takes no arguments and has no return value. Use the handler to
48        /// cancel any ongoing work and to do any required cleanup in as short a time as possible.
49        ///
50        /// - Note: The manager sets the value `expirationHandler` to `nil` after the handler completes.
51        /// - Warning: Not setting an expiration handler results in the system marking your task as complete and unsuccessful instead of sending a warning.
52        #[unsafe(method(expirationHandler))]
53        #[unsafe(method_family = none)]
54        pub unsafe fn expirationHandler(&self) -> *mut block2::DynBlock<dyn Fn()>;
55
56        #[cfg(feature = "block2")]
57        /// Setter for [`expirationHandler`][Self::expirationHandler].
58        #[unsafe(method(setExpirationHandler:))]
59        #[unsafe(method_family = none)]
60        pub unsafe fn setExpirationHandler(
61            &self,
62            expiration_handler: Option<&block2::DynBlock<dyn Fn()>>,
63        );
64
65        #[unsafe(method(init))]
66        #[unsafe(method_family = init)]
67        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
68
69        #[unsafe(method(new))]
70        #[unsafe(method_family = new)]
71        pub unsafe fn new() -> Retained<Self>;
72
73        /// Inform the background task scheduler that the task is complete.
74        ///
75        /// Call this method as soon as the background work associated with this task is complete. The system provides your app
76        /// with a limited amount of time to finish the task. If you do not call setTaskCompletedWithSuccess: on the task, the
77        /// system continues to run in the background until all the available time is consumed, wasting battery power. The
78        /// system suspends the app as soon as all background tasks are complete.
79        ///
80        /// - Parameters:
81        /// - success: A `Boolean` indicating if the task completed successfully or not. If the task was unsuccessful, you
82        /// may request the system to try again later by submitting a new task request to the scheduler before calling this
83        /// method.
84        ///
85        /// - Important: If you don’t set an expiration handler, the system will mark your task as complete and unsuccessful
86        /// instead of sending a warning.
87        /// - Warning: Not calling ``BGTask/setTaskCompletedWithSuccess:`` before the time for the task expires may result in
88        /// the system killing your app.
89        #[unsafe(method(setTaskCompletedWithSuccess:))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn setTaskCompletedWithSuccess(&self, success: bool);
92    );
93}
94
95extern_class!(
96    /// A time-consuming processing task that runs while the app is in the
97    /// background.
98    ///
99    /// Use processing tasks for long data updates, processing data, and app
100    /// maintenance. Although processing tasks can run for minutes, the system can
101    /// interrupt the process. Add an expiration handler by setting
102    /// ``BGTask/expirationHandler`` for any required cleanup.
103    ///
104    /// Executing processing tasks requires setting the `processing`
105    /// <doc
106    /// ://com.apple.documentation/documentation/bundleresources/information_property_list/uibackgroundmodes>
107    /// capability. For information on setting this capability, see
108    /// ``BGTaskScheduler``.
109    ///
110    /// Processing tasks run only when the device is idle. The system terminates any
111    /// background processing tasks running when the user starts using the device.
112    /// Background refresh tasks are not affected.
113    ///
114    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgprocessingtask?language=objc)
115    #[unsafe(super(BGTask, NSObject))]
116    #[derive(Debug, PartialEq, Eq, Hash)]
117    pub struct BGProcessingTask;
118);
119
120extern_conformance!(
121    unsafe impl NSObjectProtocol for BGProcessingTask {}
122);
123
124impl BGProcessingTask {
125    extern_methods!();
126}
127
128/// Methods declared on superclass `BGTask`.
129impl BGProcessingTask {
130    extern_methods!(
131        #[unsafe(method(init))]
132        #[unsafe(method_family = init)]
133        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
134
135        #[unsafe(method(new))]
136        #[unsafe(method_family = new)]
137        pub unsafe fn new() -> Retained<Self>;
138    );
139}
140
141extern_class!(
142    /// A task meant to perform processing on behalf of health research studies.
143    ///
144    /// Health research tasks may only be used by applications entitled to perform
145    /// studies and user's have opted in to the relevant study. These apps must have the
146    /// `com.apple.developer.backgroundtasks.healthresearch` entitlement.
147    ///
148    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bghealthresearchtask?language=objc)
149    #[unsafe(super(BGProcessingTask, BGTask, NSObject))]
150    #[derive(Debug, PartialEq, Eq, Hash)]
151    pub struct BGHealthResearchTask;
152);
153
154extern_conformance!(
155    unsafe impl NSObjectProtocol for BGHealthResearchTask {}
156);
157
158impl BGHealthResearchTask {
159    extern_methods!();
160}
161
162/// Methods declared on superclass `BGTask`.
163impl BGHealthResearchTask {
164    extern_methods!(
165        #[unsafe(method(init))]
166        #[unsafe(method_family = init)]
167        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
168
169        #[unsafe(method(new))]
170        #[unsafe(method_family = new)]
171        pub unsafe fn new() -> Retained<Self>;
172    );
173}
174
175extern_class!(
176    /// An object representing a short task typically used to refresh content that’s
177    /// run while the app is in the background.
178    ///
179    /// Use app refresh tasks for updating your app with small bits of information,
180    /// such as the latest stock values.
181    ///
182    /// Executing app refresh tasks requires setting the `fetch`
183    /// <doc
184    /// ://com.apple.documentation/documentation/bundleresources/information_property_list/uibackgroundmodes>
185    /// capability. For information on setting this capability, see
186    /// ``BGTaskScheduler``.
187    ///
188    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgapprefreshtask?language=objc)
189    #[unsafe(super(BGTask, NSObject))]
190    #[derive(Debug, PartialEq, Eq, Hash)]
191    pub struct BGAppRefreshTask;
192);
193
194extern_conformance!(
195    unsafe impl NSObjectProtocol for BGAppRefreshTask {}
196);
197
198impl BGAppRefreshTask {
199    extern_methods!();
200}
201
202/// Methods declared on superclass `BGTask`.
203impl BGAppRefreshTask {
204    extern_methods!(
205        #[unsafe(method(init))]
206        #[unsafe(method_family = init)]
207        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
208
209        #[unsafe(method(new))]
210        #[unsafe(method_family = new)]
211        pub unsafe fn new() -> Retained<Self>;
212    );
213}
214
215extern_class!(
216    /// A task meant to perform processing on behalf of a user initiated request.
217    ///
218    /// Continued processing tasks will present UI while in progress to provide awareness to the user.
219    /// ``BGContinuedProcessingTask``s _must_ report progress via the ``NSProgressReporting`` protocol conformance during
220    /// runtime and are subject to expiration based on changing system conditions and user input. Tasks that appear stalled
221    /// may be forcibly expired by the scheduler to preserve system resources.
222    ///
223    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtask?language=objc)
224    #[unsafe(super(BGTask, NSObject))]
225    #[derive(Debug, PartialEq, Eq, Hash)]
226    pub struct BGContinuedProcessingTask;
227);
228
229extern_conformance!(
230    unsafe impl NSObjectProtocol for BGContinuedProcessingTask {}
231);
232
233extern_conformance!(
234    unsafe impl NSProgressReporting for BGContinuedProcessingTask {}
235);
236
237impl BGContinuedProcessingTask {
238    extern_methods!(
239        /// The localized title displayed to the user.
240        #[unsafe(method(title))]
241        #[unsafe(method_family = none)]
242        pub unsafe fn title(&self) -> Retained<NSString>;
243
244        /// The localized subtitle displayed to the user.
245        #[unsafe(method(subtitle))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn subtitle(&self) -> Retained<NSString>;
248
249        /// Update the title and subtitle displayed in the live activity displayed to the user.
250        ///
251        /// - Parameters:
252        /// - title: The localized title displayed to the user.
253        /// - subtitle: The localized subtitle displayed to the user.
254        #[unsafe(method(updateTitle:subtitle:))]
255        #[unsafe(method_family = none)]
256        pub unsafe fn updateTitle_subtitle(&self, title: &NSString, subtitle: &NSString);
257    );
258}
259
260/// Methods declared on superclass `BGTask`.
261impl BGContinuedProcessingTask {
262    extern_methods!(
263        #[unsafe(method(init))]
264        #[unsafe(method_family = init)]
265        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
266
267        #[unsafe(method(new))]
268        #[unsafe(method_family = new)]
269        pub unsafe fn new() -> Retained<Self>;
270    );
271}