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