objc2-background-tasks 0.3.2

Bindings to the BackgroundTasks framework
Documentation
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
//! 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 that represents a request for the app to be launched in the background to perform work.
    /// Do not instantiate instances of this class directly. Instead, use one of its concrete subclasses.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgtaskrequest?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct BGTaskRequest;
);

extern_conformance!(
    unsafe impl NSCopying for BGTaskRequest {}
);

unsafe impl CopyingHelper for BGTaskRequest {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for BGTaskRequest {}
);

impl BGTaskRequest {
    extern_methods!(
        /// The identifier of the task associated with the request.
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSString>;

        /// The earliest date and time at which to run the task.
        ///
        /// Specify `nil` for no start delay.
        ///
        /// Setting the property indicates that the background task shouldn’t start any
        /// earlier than this date. However, the system doesn’t guarantee launching the
        /// task at the specified date, but only that it won’t begin sooner.
        #[unsafe(method(earliestBeginDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn earliestBeginDate(&self) -> Option<Retained<NSDate>>;

        /// Setter for [`earliestBeginDate`][Self::earliestBeginDate].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setEarliestBeginDate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEarliestBeginDate(&self, earliest_begin_date: Option<&NSDate>);

        #[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 request to launch your app in the background to execute a short refresh task.
    ///
    /// Schedule a refresh task request to ask that the system launch your app briefly so that you can download data and
    /// keep your app's contents up-to-date. The system will fulfill this request intelligently based on system conditions
    /// and app usage.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgapprefreshtaskrequest?language=objc)
    #[unsafe(super(BGTaskRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct BGAppRefreshTaskRequest;
);

extern_conformance!(
    unsafe impl NSCopying for BGAppRefreshTaskRequest {}
);

unsafe impl CopyingHelper for BGAppRefreshTaskRequest {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for BGAppRefreshTaskRequest {}
);

impl BGAppRefreshTaskRequest {
    extern_methods!(
        /// Return a new refresh task request for the specified identifier.
        ///
        /// - Parameters:
        /// - identifier: The string identifier of the refresh task associated with the request.
        #[unsafe(method(initWithIdentifier:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier(
            this: Allocated<Self>,
            identifier: &NSString,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `BGTaskRequest`.
impl BGAppRefreshTaskRequest {
    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 request to launch your app in the background to execute a processing task that can take minutes to complete.
    ///
    /// Schedule a processing task request to ask that the system launch your app when conditions are favorable for battery
    /// life to handle deferrable, longer-running processing, such as syncing, database maintenance, or similar tasks. The
    /// system will attempt to fulfill this request to the best of its ability within the next two days as long as the user
    /// has used your app within the past week.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgprocessingtaskrequest?language=objc)
    #[unsafe(super(BGTaskRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct BGProcessingTaskRequest;
);

extern_conformance!(
    unsafe impl NSCopying for BGProcessingTaskRequest {}
);

unsafe impl CopyingHelper for BGProcessingTaskRequest {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for BGProcessingTaskRequest {}
);

impl BGProcessingTaskRequest {
    extern_methods!(
        /// Return a new processing task request for the specified identifier.
        ///
        /// - Parameters:
        /// - identifier: The string identifier of the processing task associated with the request.
        #[unsafe(method(initWithIdentifier:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier(
            this: Allocated<Self>,
            identifier: &NSString,
        ) -> Retained<Self>;

        /// A Boolean specifying if the processing task requires network connectivity.
        ///
        /// If this property is set to YES, the system will only launch your app to fulfill this request when the device has a
        /// network connection. If this is set to NO, your app may not have network access.
        /// - Note: The default value is `NO`.
        #[unsafe(method(requiresNetworkConnectivity))]
        #[unsafe(method_family = none)]
        pub unsafe fn requiresNetworkConnectivity(&self) -> bool;

        /// Setter for [`requiresNetworkConnectivity`][Self::requiresNetworkConnectivity].
        #[unsafe(method(setRequiresNetworkConnectivity:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRequiresNetworkConnectivity(&self, requires_network_connectivity: bool);

        /// Whether the background task represented by this request should only be done while the device is connected to
        /// external power.
        ///
        /// If this property is set to `YES`, the system will launch your app to fulfill this request only while the device is
        /// connected to external power. Setting this to `YES` will also disable the CPU Monitor feature. Specify `YES` if this
        /// task is resource intensive to minimize impact to battery life. Please note that, even if this value is `NO`, the
        /// system will not necessarily schedule this task while the device is on battery power, depending on the type of
        /// device and system conditions.
        /// - Note: The default value is `NO`.
        #[unsafe(method(requiresExternalPower))]
        #[unsafe(method_family = none)]
        pub unsafe fn requiresExternalPower(&self) -> bool;

        /// Setter for [`requiresExternalPower`][Self::requiresExternalPower].
        #[unsafe(method(setRequiresExternalPower:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRequiresExternalPower(&self, requires_external_power: bool);
    );
}

/// Methods declared on superclass `BGTaskRequest`.
impl BGProcessingTaskRequest {
    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 request to launch your app in the background to execute a health research task for studies a user has opted into
    /// and that can take minutes to complete.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bghealthresearchtaskrequest?language=objc)
    #[unsafe(super(BGProcessingTaskRequest, BGTaskRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct BGHealthResearchTaskRequest;
);

extern_conformance!(
    unsafe impl NSCopying for BGHealthResearchTaskRequest {}
);

unsafe impl CopyingHelper for BGHealthResearchTaskRequest {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for BGHealthResearchTaskRequest {}
);

impl BGHealthResearchTaskRequest {
    extern_methods!(
        /// A String indicating file protection availability required for processing.
        ///
        /// Update this property to indicate what type of data needs to be accessible when the task is run. The default value
        /// is `NSFileProtectionCompleteUntilFirstUserAuthentication`
        ///
        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(protectionTypeOfRequiredData))]
        #[unsafe(method_family = none)]
        pub unsafe fn protectionTypeOfRequiredData(&self) -> Retained<NSFileProtectionType>;

        /// Setter for [`protectionTypeOfRequiredData`][Self::protectionTypeOfRequiredData].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setProtectionTypeOfRequiredData:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setProtectionTypeOfRequiredData(
            &self,
            protection_type_of_required_data: &NSFileProtectionType,
        );
    );
}

/// Methods declared on superclass `BGProcessingTaskRequest`.
impl BGHealthResearchTaskRequest {
    extern_methods!(
        /// Return a new processing task request for the specified identifier.
        ///
        /// - Parameters:
        /// - identifier: The string identifier of the processing task associated with the request.
        #[unsafe(method(initWithIdentifier:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier(
            this: Allocated<Self>,
            identifier: &NSString,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `BGTaskRequest`.
impl BGHealthResearchTaskRequest {
    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>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequestsubmissionstrategy?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct BGContinuedProcessingTaskRequestSubmissionStrategy(pub NSInteger);
impl BGContinuedProcessingTaskRequestSubmissionStrategy {
    /// Fail the submission if there is no room for the task request, or if the system is under substantial load and is
    /// unable immediately run the task.
    #[doc(alias = "BGContinuedProcessingTaskRequestSubmissionStrategyFail")]
    pub const Fail: Self = Self(0);
    /// Add the request to the back of a queue if there is no room for the submitted task or if the system is under
    /// substantial load and is unable to immediately run the task. Queued ``BGContinuedProcessingTaskRequest``s will be
    /// cancelled when the user removes your app from the app switcher.
    #[doc(alias = "BGContinuedProcessingTaskRequestSubmissionStrategyQueue")]
    pub const Queue: Self = Self(1);
}

unsafe impl Encode for BGContinuedProcessingTaskRequestSubmissionStrategy {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for BGContinuedProcessingTaskRequestSubmissionStrategy {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequestresources?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct BGContinuedProcessingTaskRequestResources(pub NSInteger);
bitflags::bitflags! {
    impl BGContinuedProcessingTaskRequestResources: NSInteger {
/// No special system resources required.
///
/// Unless informed otherwise, the scheduler assumes the default resources, allowing background CPU and network
/// access.
        #[doc(alias = "BGContinuedProcessingTaskRequestResourcesDefault")]
        const Default = 0;
/// Indicate to the scheduler that the workload will require background GPU utilization.
///
/// Task submissions will be rejected if the submitting app does not have the correct entitlement. Background GPU
/// execution is not supported on all devices. Additionally, if a device is experiencing heavy GPU contention
/// backgrounded workloads are not guaranteed runtime.
///
/// - Important: Applications must have the `com.apple.developer.background-tasks.continued-processing.gpu`  entitlement to submit a task request with this resource.
        #[doc(alias = "BGContinuedProcessingTaskRequestResourcesGPU")]
        const GPU = 1<<0;
    }
}

unsafe impl Encode for BGContinuedProcessingTaskRequestResources {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for BGContinuedProcessingTaskRequestResources {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// A request to begin a workload immediately, or shortly after submission, which is allowed to continue running even if
    /// the app is backgrounded.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/backgroundtasks/bgcontinuedprocessingtaskrequest?language=objc)
    #[unsafe(super(BGTaskRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct BGContinuedProcessingTaskRequest;
);

extern_conformance!(
    unsafe impl NSCopying for BGContinuedProcessingTaskRequest {}
);

unsafe impl CopyingHelper for BGContinuedProcessingTaskRequest {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for BGContinuedProcessingTaskRequest {}
);

impl BGContinuedProcessingTaskRequest {
    extern_methods!(
        /// The localized title displayed to the user.
        #[unsafe(method(title))]
        #[unsafe(method_family = none)]
        pub unsafe fn title(&self) -> Retained<NSString>;

        /// Setter for [`title`][Self::title].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setTitle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTitle(&self, title: &NSString);

        /// The localized subtitle displayed to the user.
        #[unsafe(method(subtitle))]
        #[unsafe(method_family = none)]
        pub unsafe fn subtitle(&self) -> Retained<NSString>;

        /// Setter for [`subtitle`][Self::subtitle].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setSubtitle:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSubtitle(&self, subtitle: &NSString);

        /// The submission strategy for the scheduler to abide by.
        ///
        /// Defaults to ``BGContinuedProcessingTaskRequestSubmissionStrategy/BGContinuedProcessingTaskRequestSubmissionStrategyQueue``.
        #[unsafe(method(strategy))]
        #[unsafe(method_family = none)]
        pub unsafe fn strategy(&self) -> BGContinuedProcessingTaskRequestSubmissionStrategy;

        /// Setter for [`strategy`][Self::strategy].
        #[unsafe(method(setStrategy:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setStrategy(
            &self,
            strategy: BGContinuedProcessingTaskRequestSubmissionStrategy,
        );

        /// Inform the scheduler that the task will be requesting additional system resources.
        ///
        /// Defaults to ``BGContinuedProcessingTaskRequestResources/BGContinuedProcessingTaskRequestResourcesDefault``.
        #[unsafe(method(requiredResources))]
        #[unsafe(method_family = none)]
        pub unsafe fn requiredResources(&self) -> BGContinuedProcessingTaskRequestResources;

        /// Setter for [`requiredResources`][Self::requiredResources].
        #[unsafe(method(setRequiredResources:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRequiredResources(
            &self,
            required_resources: BGContinuedProcessingTaskRequestResources,
        );

        /// Creates an instance on behalf of the currently foregrounded app.
        ///
        /// Apps and their extensions should use this method to initialize any tasks due to the underlying association to the
        /// currently foregrounded app. Please note that ``BGTaskRequest/earliestBeginDate`` will be outright ignored by the
        /// scheduler in favor of `NSDate.now`.
        ///
        /// The identifier ought to use wildcard notation, where the prefix of the identifier must at least contain the bundle
        /// ID of the submitting application, followed by optional semantic context, and finally ending with `.*`. An example:
        /// `
        /// <MainBundle
        /// >.
        /// <SemanticContext
        /// >.*` which would transform to `com.foo.MyApplication.continuedProcessingTask.*`. Thus,
        /// a submitted identifier would be of the form `com.foo.MyApplication.continuedProcessingTask.HD830D`.
        ///
        /// - Parameters:
        /// - identifier: The task identifier.
        /// - title: The localized title displayed to the user before the task begins running.
        /// - subtitle: The localized subtitle displayed to the user before the task begins running.
        /// - Warning: Successful creation of this object does not guarantee successful submission to the scheduler.
        #[unsafe(method(initWithIdentifier:title:subtitle:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier_title_subtitle(
            this: Allocated<Self>,
            identifier: &NSString,
            title: &NSString,
            subtitle: &NSString,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `BGTaskRequest`.
impl BGContinuedProcessingTaskRequest {
    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>;
    );
}