objc2_background_tasks/generated/BGTaskRequest.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 that represents a request for the app to be launched in the background to perform work.
12 /// Do not instantiate instances of this class directly. Instead, use one of its concrete subclasses.
13 ///
14 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtaskrequest?language=objc)
15 #[unsafe(super(NSObject))]
16 #[derive(Debug, PartialEq, Eq, Hash)]
17 pub struct BGTaskRequest;
18);
19
20extern_conformance!(
21 unsafe impl NSCopying for BGTaskRequest {}
22);
23
24unsafe impl CopyingHelper for BGTaskRequest {
25 type Result = Self;
26}
27
28extern_conformance!(
29 unsafe impl NSObjectProtocol for BGTaskRequest {}
30);
31
32impl BGTaskRequest {
33 extern_methods!(
34 /// The identifier of the task associated with the request.
35 #[unsafe(method(identifier))]
36 #[unsafe(method_family = none)]
37 pub unsafe fn identifier(&self) -> Retained<NSString>;
38
39 /// The earliest date and time at which to run the task.
40 ///
41 /// Specify `nil` for no start delay.
42 ///
43 /// Setting the property indicates that the background task shouldn’t start any
44 /// earlier than this date. However, the system doesn’t guarantee launching the
45 /// task at the specified date, but only that it won’t begin sooner.
46 #[unsafe(method(earliestBeginDate))]
47 #[unsafe(method_family = none)]
48 pub unsafe fn earliestBeginDate(&self) -> Option<Retained<NSDate>>;
49
50 /// Setter for [`earliestBeginDate`][Self::earliestBeginDate].
51 ///
52 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
53 #[unsafe(method(setEarliestBeginDate:))]
54 #[unsafe(method_family = none)]
55 pub unsafe fn setEarliestBeginDate(&self, earliest_begin_date: Option<&NSDate>);
56
57 #[unsafe(method(init))]
58 #[unsafe(method_family = init)]
59 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
60
61 #[unsafe(method(new))]
62 #[unsafe(method_family = new)]
63 pub unsafe fn new() -> Retained<Self>;
64 );
65}
66
67extern_class!(
68 /// A request to launch your app in the background to execute a short refresh task.
69 ///
70 /// Schedule a refresh task request to ask that the system launch your app briefly so that you can download data and
71 /// keep your app's contents up-to-date. The system will fulfill this request intelligently based on system conditions
72 /// and app usage.
73 ///
74 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgapprefreshtaskrequest?language=objc)
75 #[unsafe(super(BGTaskRequest, NSObject))]
76 #[derive(Debug, PartialEq, Eq, Hash)]
77 pub struct BGAppRefreshTaskRequest;
78);
79
80extern_conformance!(
81 unsafe impl NSCopying for BGAppRefreshTaskRequest {}
82);
83
84unsafe impl CopyingHelper for BGAppRefreshTaskRequest {
85 type Result = Self;
86}
87
88extern_conformance!(
89 unsafe impl NSObjectProtocol for BGAppRefreshTaskRequest {}
90);
91
92impl BGAppRefreshTaskRequest {
93 extern_methods!(
94 /// Return a new refresh task request for the specified identifier.
95 ///
96 /// - Parameters:
97 /// - identifier: The string identifier of the refresh task associated with the request.
98 #[unsafe(method(initWithIdentifier:))]
99 #[unsafe(method_family = init)]
100 pub unsafe fn initWithIdentifier(
101 this: Allocated<Self>,
102 identifier: &NSString,
103 ) -> Retained<Self>;
104 );
105}
106
107/// Methods declared on superclass `BGTaskRequest`.
108impl BGAppRefreshTaskRequest {
109 extern_methods!(
110 #[unsafe(method(init))]
111 #[unsafe(method_family = init)]
112 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
113
114 #[unsafe(method(new))]
115 #[unsafe(method_family = new)]
116 pub unsafe fn new() -> Retained<Self>;
117 );
118}
119
120extern_class!(
121 /// A request to launch your app in the background to execute a processing task that can take minutes to complete.
122 ///
123 /// Schedule a processing task request to ask that the system launch your app when conditions are favorable for battery
124 /// life to handle deferrable, longer-running processing, such as syncing, database maintenance, or similar tasks. The
125 /// system will attempt to fulfill this request to the best of its ability within the next two days as long as the user
126 /// has used your app within the past week.
127 ///
128 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgprocessingtaskrequest?language=objc)
129 #[unsafe(super(BGTaskRequest, NSObject))]
130 #[derive(Debug, PartialEq, Eq, Hash)]
131 pub struct BGProcessingTaskRequest;
132);
133
134extern_conformance!(
135 unsafe impl NSCopying for BGProcessingTaskRequest {}
136);
137
138unsafe impl CopyingHelper for BGProcessingTaskRequest {
139 type Result = Self;
140}
141
142extern_conformance!(
143 unsafe impl NSObjectProtocol for BGProcessingTaskRequest {}
144);
145
146impl BGProcessingTaskRequest {
147 extern_methods!(
148 /// Return a new processing task request for the specified identifier.
149 ///
150 /// - Parameters:
151 /// - identifier: The string identifier of the processing task associated with the request.
152 #[unsafe(method(initWithIdentifier:))]
153 #[unsafe(method_family = init)]
154 pub unsafe fn initWithIdentifier(
155 this: Allocated<Self>,
156 identifier: &NSString,
157 ) -> Retained<Self>;
158
159 /// A Boolean specifying if the processing task requires network connectivity.
160 ///
161 /// If this property is set to YES, the system will only launch your app to fulfill this request when the device has a
162 /// network connection. If this is set to NO, your app may not have network access.
163 /// - Note: The default value is `NO`.
164 #[unsafe(method(requiresNetworkConnectivity))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn requiresNetworkConnectivity(&self) -> bool;
167
168 /// Setter for [`requiresNetworkConnectivity`][Self::requiresNetworkConnectivity].
169 #[unsafe(method(setRequiresNetworkConnectivity:))]
170 #[unsafe(method_family = none)]
171 pub unsafe fn setRequiresNetworkConnectivity(&self, requires_network_connectivity: bool);
172
173 /// Whether the background task represented by this request should only be done while the device is connected to
174 /// external power.
175 ///
176 /// If this property is set to `YES`, the system will launch your app to fulfill this request only while the device is
177 /// connected to external power. Setting this to `YES` will also disable the CPU Monitor feature. Specify `YES` if this
178 /// task is resource intensive to minimize impact to battery life. Please note that, even if this value is `NO`, the
179 /// system will not necessarily schedule this task while the device is on battery power, depending on the type of
180 /// device and system conditions.
181 /// - Note: The default value is `NO`.
182 #[unsafe(method(requiresExternalPower))]
183 #[unsafe(method_family = none)]
184 pub unsafe fn requiresExternalPower(&self) -> bool;
185
186 /// Setter for [`requiresExternalPower`][Self::requiresExternalPower].
187 #[unsafe(method(setRequiresExternalPower:))]
188 #[unsafe(method_family = none)]
189 pub unsafe fn setRequiresExternalPower(&self, requires_external_power: bool);
190 );
191}
192
193/// Methods declared on superclass `BGTaskRequest`.
194impl BGProcessingTaskRequest {
195 extern_methods!(
196 #[unsafe(method(init))]
197 #[unsafe(method_family = init)]
198 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
199
200 #[unsafe(method(new))]
201 #[unsafe(method_family = new)]
202 pub unsafe fn new() -> Retained<Self>;
203 );
204}
205
206extern_class!(
207 /// A request to launch your app in the background to execute a health research task for studies a user has opted into
208 /// and that can take minutes to complete.
209 ///
210 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bghealthresearchtaskrequest?language=objc)
211 #[unsafe(super(BGProcessingTaskRequest, BGTaskRequest, NSObject))]
212 #[derive(Debug, PartialEq, Eq, Hash)]
213 pub struct BGHealthResearchTaskRequest;
214);
215
216extern_conformance!(
217 unsafe impl NSCopying for BGHealthResearchTaskRequest {}
218);
219
220unsafe impl CopyingHelper for BGHealthResearchTaskRequest {
221 type Result = Self;
222}
223
224extern_conformance!(
225 unsafe impl NSObjectProtocol for BGHealthResearchTaskRequest {}
226);
227
228impl BGHealthResearchTaskRequest {
229 extern_methods!(
230 /// A String indicating file protection availability required for processing.
231 ///
232 /// Update this property to indicate what type of data needs to be accessible when the task is run. The default value
233 /// is `NSFileProtectionCompleteUntilFirstUserAuthentication`
234 ///
235 /// # Safety
236 ///
237 /// This is not retained internally, you must ensure the object is still alive.
238 #[unsafe(method(protectionTypeOfRequiredData))]
239 #[unsafe(method_family = none)]
240 pub unsafe fn protectionTypeOfRequiredData(&self) -> Retained<NSFileProtectionType>;
241
242 /// Setter for [`protectionTypeOfRequiredData`][Self::protectionTypeOfRequiredData].
243 ///
244 /// # Safety
245 ///
246 /// This is unretained, you must ensure the object is kept alive while in use.
247 #[unsafe(method(setProtectionTypeOfRequiredData:))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn setProtectionTypeOfRequiredData(
250 &self,
251 protection_type_of_required_data: &NSFileProtectionType,
252 );
253 );
254}
255
256/// Methods declared on superclass `BGProcessingTaskRequest`.
257impl BGHealthResearchTaskRequest {
258 extern_methods!(
259 /// Return a new processing task request for the specified identifier.
260 ///
261 /// - Parameters:
262 /// - identifier: The string identifier of the processing task associated with the request.
263 #[unsafe(method(initWithIdentifier:))]
264 #[unsafe(method_family = init)]
265 pub unsafe fn initWithIdentifier(
266 this: Allocated<Self>,
267 identifier: &NSString,
268 ) -> Retained<Self>;
269 );
270}
271
272/// Methods declared on superclass `BGTaskRequest`.
273impl BGHealthResearchTaskRequest {
274 extern_methods!(
275 #[unsafe(method(init))]
276 #[unsafe(method_family = init)]
277 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
278
279 #[unsafe(method(new))]
280 #[unsafe(method_family = new)]
281 pub unsafe fn new() -> Retained<Self>;
282 );
283}
284
285/// [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequestsubmissionstrategy?language=objc)
286// NS_ENUM
287#[repr(transparent)]
288#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
289pub struct BGContinuedProcessingTaskRequestSubmissionStrategy(pub NSInteger);
290impl BGContinuedProcessingTaskRequestSubmissionStrategy {
291 /// Fail the submission if there is no room for the task request, or if the system is under substantial load and is
292 /// unable immediately run the task.
293 #[doc(alias = "BGContinuedProcessingTaskRequestSubmissionStrategyFail")]
294 pub const Fail: Self = Self(0);
295 /// Add the request to the back of a queue if there is no room for the submitted task or if the system is under
296 /// substantial load and is unable to immediately run the task. Queued ``BGContinuedProcessingTaskRequest``s will be
297 /// cancelled when the user removes your app from the app switcher.
298 #[doc(alias = "BGContinuedProcessingTaskRequestSubmissionStrategyQueue")]
299 pub const Queue: Self = Self(1);
300}
301
302unsafe impl Encode for BGContinuedProcessingTaskRequestSubmissionStrategy {
303 const ENCODING: Encoding = NSInteger::ENCODING;
304}
305
306unsafe impl RefEncode for BGContinuedProcessingTaskRequestSubmissionStrategy {
307 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
308}
309
310/// [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequestresources?language=objc)
311// NS_OPTIONS
312#[repr(transparent)]
313#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
314pub struct BGContinuedProcessingTaskRequestResources(pub NSInteger);
315bitflags::bitflags! {
316 impl BGContinuedProcessingTaskRequestResources: NSInteger {
317/// No special system resources required.
318///
319/// Unless informed otherwise, the scheduler assumes the default resources, allowing background CPU and network
320/// access.
321 #[doc(alias = "BGContinuedProcessingTaskRequestResourcesDefault")]
322 const Default = 0;
323/// Indicate to the scheduler that the workload will require background GPU utilization.
324///
325/// Task submissions will be rejected if the submitting app does not have the correct entitlement. Background GPU
326/// execution is not supported on all devices. Additionally, if a device is experiencing heavy GPU contention
327/// backgrounded workloads are not guaranteed runtime.
328///
329/// - Important: Applications must have the `com.apple.developer.background-tasks.continued-processing.gpu` entitlement to submit a task request with this resource.
330 #[doc(alias = "BGContinuedProcessingTaskRequestResourcesGPU")]
331 const GPU = 1<<0;
332 }
333}
334
335unsafe impl Encode for BGContinuedProcessingTaskRequestResources {
336 const ENCODING: Encoding = NSInteger::ENCODING;
337}
338
339unsafe impl RefEncode for BGContinuedProcessingTaskRequestResources {
340 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
341}
342
343extern_class!(
344 /// A request to begin a workload immediately, or shortly after submission, which is allowed to continue running even if
345 /// the app is backgrounded.
346 ///
347 /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequest?language=objc)
348 #[unsafe(super(BGTaskRequest, NSObject))]
349 #[derive(Debug, PartialEq, Eq, Hash)]
350 pub struct BGContinuedProcessingTaskRequest;
351);
352
353extern_conformance!(
354 unsafe impl NSCopying for BGContinuedProcessingTaskRequest {}
355);
356
357unsafe impl CopyingHelper for BGContinuedProcessingTaskRequest {
358 type Result = Self;
359}
360
361extern_conformance!(
362 unsafe impl NSObjectProtocol for BGContinuedProcessingTaskRequest {}
363);
364
365impl BGContinuedProcessingTaskRequest {
366 extern_methods!(
367 /// The localized title displayed to the user.
368 #[unsafe(method(title))]
369 #[unsafe(method_family = none)]
370 pub unsafe fn title(&self) -> Retained<NSString>;
371
372 /// Setter for [`title`][Self::title].
373 ///
374 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
375 #[unsafe(method(setTitle:))]
376 #[unsafe(method_family = none)]
377 pub unsafe fn setTitle(&self, title: &NSString);
378
379 /// The localized subtitle displayed to the user.
380 #[unsafe(method(subtitle))]
381 #[unsafe(method_family = none)]
382 pub unsafe fn subtitle(&self) -> Retained<NSString>;
383
384 /// Setter for [`subtitle`][Self::subtitle].
385 ///
386 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
387 #[unsafe(method(setSubtitle:))]
388 #[unsafe(method_family = none)]
389 pub unsafe fn setSubtitle(&self, subtitle: &NSString);
390
391 /// The submission strategy for the scheduler to abide by.
392 ///
393 /// Defaults to ``BGContinuedProcessingTaskRequestSubmissionStrategy/BGContinuedProcessingTaskRequestSubmissionStrategyQueue``.
394 #[unsafe(method(strategy))]
395 #[unsafe(method_family = none)]
396 pub unsafe fn strategy(&self) -> BGContinuedProcessingTaskRequestSubmissionStrategy;
397
398 /// Setter for [`strategy`][Self::strategy].
399 #[unsafe(method(setStrategy:))]
400 #[unsafe(method_family = none)]
401 pub unsafe fn setStrategy(
402 &self,
403 strategy: BGContinuedProcessingTaskRequestSubmissionStrategy,
404 );
405
406 /// Inform the scheduler that the task will be requesting additional system resources.
407 ///
408 /// Defaults to ``BGContinuedProcessingTaskRequestResources/BGContinuedProcessingTaskRequestResourcesDefault``.
409 #[unsafe(method(requiredResources))]
410 #[unsafe(method_family = none)]
411 pub unsafe fn requiredResources(&self) -> BGContinuedProcessingTaskRequestResources;
412
413 /// Setter for [`requiredResources`][Self::requiredResources].
414 #[unsafe(method(setRequiredResources:))]
415 #[unsafe(method_family = none)]
416 pub unsafe fn setRequiredResources(
417 &self,
418 required_resources: BGContinuedProcessingTaskRequestResources,
419 );
420
421 /// Creates an instance on behalf of the currently foregrounded app.
422 ///
423 /// Apps and their extensions should use this method to initialize any tasks due to the underlying association to the
424 /// currently foregrounded app. Please note that ``BGTaskRequest/earliestBeginDate`` will be outright ignored by the
425 /// scheduler in favor of `NSDate.now`.
426 ///
427 /// The identifier ought to use wildcard notation, where the prefix of the identifier must at least contain the bundle
428 /// ID of the submitting application, followed by optional semantic context, and finally ending with `.*`. An example:
429 /// `
430 /// <MainBundle
431 /// >.
432 /// <SemanticContext
433 /// >.*` which would transform to `com.foo.MyApplication.continuedProcessingTask.*`. Thus,
434 /// a submitted identifier would be of the form `com.foo.MyApplication.continuedProcessingTask.HD830D`.
435 ///
436 /// - Parameters:
437 /// - identifier: The task identifier.
438 /// - title: The localized title displayed to the user before the task begins running.
439 /// - subtitle: The localized subtitle displayed to the user before the task begins running.
440 /// - Warning: Successful creation of this object does not guarantee successful submission to the scheduler.
441 #[unsafe(method(initWithIdentifier:title:subtitle:))]
442 #[unsafe(method_family = init)]
443 pub unsafe fn initWithIdentifier_title_subtitle(
444 this: Allocated<Self>,
445 identifier: &NSString,
446 title: &NSString,
447 subtitle: &NSString,
448 ) -> Retained<Self>;
449 );
450}
451
452/// Methods declared on superclass `BGTaskRequest`.
453impl BGContinuedProcessingTaskRequest {
454 extern_methods!(
455 #[unsafe(method(init))]
456 #[unsafe(method_family = init)]
457 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
458
459 #[unsafe(method(new))]
460 #[unsafe(method_family = new)]
461 pub unsafe fn new() -> Retained<Self>;
462 );
463}