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 /// The time allocated by the system for expiration handlers doesn’t vary with
38 /// the number of background tasks. All expiration handlers must complete before
39 /// the allocated time.
40 ///
41 /// Not setting an expiration handler results in the system marking your task as
42 /// complete and unsuccessful instead of sending a warning.
43 ///
44 /// The manager sets the value `expirationHandler` to `nil` after the handler
45 /// completes.
46 ///
47 /// - Parameters:
48 /// - expirationHandler: The expiration handler takes no arguments and has no
49 /// return value. Use the handler to cancel any ongoing work and to do any
50 /// required cleanup in as short a time as possible.
51 ///
52 /// The handler may be called before the background process uses the full amount of its
53 /// allocated time.
54 #[unsafe(method(expirationHandler))]
55 #[unsafe(method_family = none)]
56 pub unsafe fn expirationHandler(&self) -> *mut block2::DynBlock<dyn Fn()>;
57
58 #[cfg(feature = "block2")]
59 /// Setter for [`expirationHandler`][Self::expirationHandler].
60 #[unsafe(method(setExpirationHandler:))]
61 #[unsafe(method_family = none)]
62 pub unsafe fn setExpirationHandler(
63 &self,
64 expiration_handler: Option<&block2::DynBlock<dyn Fn()>>,
65 );
66
67 #[unsafe(method(init))]
68 #[unsafe(method_family = init)]
69 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
70
71 #[unsafe(method(new))]
72 #[unsafe(method_family = new)]
73 pub unsafe fn new() -> Retained<Self>;
74
75 /// Informs the background task scheduler that the task is complete.
76 ///
77 /// Not calling ``BGTask/setTaskCompletedWithSuccess:`` before the time for the
78 /// task expires may result in the system killing your app.
79 ///
80 /// You can reschedule an unsuccessful required task.
81 ///
82 /// - Important: If you don’t set an expiration handler, the system will mark
83 /// your task as complete and unsuccessful instead of sending a warning.
84 ///
85 /// - Parameters:
86 /// - success: A `Boolean` indicating if the task completed successfully or not.
87 #[unsafe(method(setTaskCompletedWithSuccess:))]
88 #[unsafe(method_family = none)]
89 pub unsafe fn setTaskCompletedWithSuccess(&self, success: bool);
90 );
91}
92
93extern_class!(
94 /// A time-consuming processing task that runs while the app is in the
95 /// background.
96 ///
97 /// Use processing tasks for long data updates, processing data, and app
98 /// maintenance. Although processing tasks can run for minutes, the system can
99 /// interrupt the process. Add an expiration handler by setting
100 /// ``BGTask/expirationHandler`` for any required cleanup.
101 ///
102 /// Executing processing tasks requires setting the `processing`
103 /// <doc
104 /// ://com.apple.documentation/documentation/bundleresources/information_property_list/uibackgroundmodes>
105 /// capability. For information on setting this capability, see
106 /// ``BGTaskScheduler``.
107 ///
108 /// Processing tasks run only when the device is idle. The system terminates any
109 /// background processing tasks running when the user starts using the device.
110 /// Background refresh tasks are not affected.
111 ///
112 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgprocessingtask?language=objc)
113 #[unsafe(super(BGTask, NSObject))]
114 #[derive(Debug, PartialEq, Eq, Hash)]
115 pub struct BGProcessingTask;
116);
117
118extern_conformance!(
119 unsafe impl NSObjectProtocol for BGProcessingTask {}
120);
121
122impl BGProcessingTask {
123 extern_methods!();
124}
125
126/// Methods declared on superclass `BGTask`.
127impl BGProcessingTask {
128 extern_methods!(
129 #[unsafe(method(init))]
130 #[unsafe(method_family = init)]
131 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
132
133 #[unsafe(method(new))]
134 #[unsafe(method_family = new)]
135 pub unsafe fn new() -> Retained<Self>;
136 );
137}
138
139extern_class!(
140 /// A task meant to perform processing on behalf of health research studies.
141 ///
142 /// Health research tasks may only be used by applications entitled to perform
143 /// studies and user's have opted in to the relevant study. These apps must have the
144 /// `com.apple.developer.backgroundtasks.healthresearch` entitlement.
145 ///
146 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bghealthresearchtask?language=objc)
147 #[unsafe(super(BGProcessingTask, BGTask, NSObject))]
148 #[derive(Debug, PartialEq, Eq, Hash)]
149 pub struct BGHealthResearchTask;
150);
151
152extern_conformance!(
153 unsafe impl NSObjectProtocol for BGHealthResearchTask {}
154);
155
156impl BGHealthResearchTask {
157 extern_methods!();
158}
159
160/// Methods declared on superclass `BGTask`.
161impl BGHealthResearchTask {
162 extern_methods!(
163 #[unsafe(method(init))]
164 #[unsafe(method_family = init)]
165 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
166
167 #[unsafe(method(new))]
168 #[unsafe(method_family = new)]
169 pub unsafe fn new() -> Retained<Self>;
170 );
171}
172
173extern_class!(
174 /// An object representing a short task typically used to refresh content that’s
175 /// run while the app is in the background.
176 ///
177 /// Use app refresh tasks for updating your app with small bits of information,
178 /// such as the latest stock values.
179 ///
180 /// Executing app refresh tasks requires setting the `fetch`
181 /// <doc
182 /// ://com.apple.documentation/documentation/bundleresources/information_property_list/uibackgroundmodes>
183 /// capability. For information on setting this capability, see
184 /// ``BGTaskScheduler``.
185 ///
186 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgapprefreshtask?language=objc)
187 #[unsafe(super(BGTask, NSObject))]
188 #[derive(Debug, PartialEq, Eq, Hash)]
189 pub struct BGAppRefreshTask;
190);
191
192extern_conformance!(
193 unsafe impl NSObjectProtocol for BGAppRefreshTask {}
194);
195
196impl BGAppRefreshTask {
197 extern_methods!();
198}
199
200/// Methods declared on superclass `BGTask`.
201impl BGAppRefreshTask {
202 extern_methods!(
203 #[unsafe(method(init))]
204 #[unsafe(method_family = init)]
205 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
206
207 #[unsafe(method(new))]
208 #[unsafe(method_family = new)]
209 pub unsafe fn new() -> Retained<Self>;
210 );
211}