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