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
//! 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_protocol!(
/// [Apple's documentation](https://developer.apple.com/documentation/backgroundassets/badownloadmanagerdelegate?language=objc)
pub unsafe trait BADownloadManagerDelegate: NSObjectProtocol {
#[cfg(feature = "BADownload")]
/// A download has started.
#[optional]
#[unsafe(method(downloadDidBegin:))]
#[unsafe(method_family = none)]
unsafe fn downloadDidBegin(&self, download: &BADownload);
#[cfg(feature = "BADownload")]
/// A download has paused.
#[optional]
#[unsafe(method(downloadDidPause:))]
#[unsafe(method_family = none)]
unsafe fn downloadDidPause(&self, download: &BADownload);
#[cfg(feature = "BADownload")]
/// A download has made progress in bytes / total so far / total expected.
#[optional]
#[unsafe(method(download:didWriteBytes:totalBytesWritten:totalBytesExpectedToWrite:))]
#[unsafe(method_family = none)]
unsafe fn download_didWriteBytes_totalBytesWritten_totalBytesExpectedToWrite(
&self,
download: &BADownload,
bytes_written: i64,
total_bytes_written: i64,
total_expected_bytes: i64,
);
#[cfg(all(feature = "BADownload", feature = "block2"))]
/// A download has tried to start but gotten a challenge quest.
#[optional]
#[unsafe(method(download:didReceiveChallenge:completionHandler:))]
#[unsafe(method_family = none)]
unsafe fn download_didReceiveChallenge_completionHandler(
&self,
download: &BADownload,
challenge: &NSURLAuthenticationChallenge,
completion_handler: &block2::DynBlock<
dyn Fn(NSURLSessionAuthChallengeDisposition, *mut NSURLCredential),
>,
);
#[cfg(feature = "BADownload")]
/// A download has failed with a specific error.
#[optional]
#[unsafe(method(download:failedWithError:))]
#[unsafe(method_family = none)]
unsafe fn download_failedWithError(&self, download: &BADownload, error: &NSError);
#[cfg(feature = "BADownload")]
/// Download has finished.
///
/// Parameter `fileURL`: A location to the file that has been downloaded.
///
/// The file located at `fileURL` must be moved before this method exits scope, or it will be deleted.
/// It is strongly advised to move the file to its permanent destination rather than copy it.
///
/// Warning: The file is marked by the system for deletion when the device becomes low on storage. Avoid copying or modifying
/// the file, as this may remove the system's ability to delete the file.
#[optional]
#[unsafe(method(download:finishedWithFileURL:))]
#[unsafe(method_family = none)]
unsafe fn download_finishedWithFileURL(&self, download: &BADownload, file_url: &NSURL);
}
);
extern_class!(
/// [Apple's documentation](https://developer.apple.com/documentation/backgroundassets/badownloadmanager?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct BADownloadManager;
);
extern_conformance!(
unsafe impl NSObjectProtocol for BADownloadManager {}
);
impl BADownloadManager {
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>;
/// Gets the singleton downloader object.
#[unsafe(method(sharedManager))]
#[unsafe(method_family = none)]
pub unsafe fn sharedManager() -> Retained<BADownloadManager>;
/// A object confroming to BADownloadManagerDelegate to get notified when actions occur.
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub unsafe fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn BADownloadManagerDelegate>>>;
/// Setter for [`delegate`][Self::delegate].
///
/// This is a [weak property][objc2::topics::weak_property].
#[unsafe(method(setDelegate:))]
#[unsafe(method_family = none)]
pub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn BADownloadManagerDelegate>>,
);
#[cfg(feature = "BADownload")]
/// Fetches current downloads.
///
/// Fetches the current list of scheduled or in-flight downloads queued by your application or extension.
///
/// Parameter `error`: An error representing why the downloads could not be fetched.
///
/// Returns: On success, returns a list of scheduled or in-flight downloads. On failure, returns nil and sets
/// `error.`
/// Warning: This method can block and should not be called from the main thread.
///
/// See also: BADownloadManager:fetchCurrentDownloadsWithCompletionHandler
#[unsafe(method(fetchCurrentDownloads:_))]
#[unsafe(method_family = none)]
pub unsafe fn fetchCurrentDownloads(
&self,
) -> Result<Retained<NSArray<BADownload>>, Retained<NSError>>;
#[cfg(all(feature = "BADownload", feature = "block2"))]
/// Fetches current downloads.
///
/// Fetches the current list of scheduled or in-flight downloads queued by your application or extension.
///
/// Parameter `completionHandler`: A block to recieve the currently scheduled or in-flight downloads. The block is called on the same queue as all the other completion blocks in the class.
///
/// # Safety
///
/// `completion_handler` block must be sendable.
#[unsafe(method(fetchCurrentDownloadsWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn fetchCurrentDownloadsWithCompletionHandler(
&self,
completion_handler: &block2::DynBlock<
dyn Fn(NonNull<NSArray<BADownload>>, *mut NSError),
>,
);
#[cfg(feature = "BADownload")]
/// Schedules a background download.
///
/// Specifies a download to schedule at a given priority. The download will automatically
/// start at the discretion of the system.
///
/// Parameter `download`: A BADownload object representing a URL to be downloaded.
///
/// Parameter `error`: A NSError representing why the BADownload could not be scheduled.
///
/// Returns: YES if
/// `download`was scheduled. NO and
/// `error`set if the download could not be scheduled.
#[unsafe(method(scheduleDownload:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn scheduleDownload_error(
&self,
download: &BADownload,
) -> Result<(), Retained<NSError>>;
#[cfg(feature = "block2")]
/// Acquires exclusive access to the BADownloadManager across the app and application extension.
///
/// Acquires exclusive access to the BADownloadManager across the app and application extension. This ensures that your extension and app
/// do not perform operations at the same time. Both the extension and app must use this API to ensure exclusive access.
///
/// Parameter `performHandler`: A block that will be executed once exclusive control is acquired.
/// If an error is non-nil then a problem occurred acquiring exclusive access.
///
/// # Safety
///
/// `perform_handler` block must be sendable.
#[unsafe(method(performWithExclusiveControl:))]
#[unsafe(method_family = none)]
pub unsafe fn performWithExclusiveControl(
&self,
perform_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// Acquires exclusive access to the BADownloadManager across the app and application extension.
///
/// Acquires exclusive access to the BADownloadManager across the app and application extension. This ensures that your extension and app
/// do not perform operations at the same time. Both the extension and app must use this API to ensure exclusive access.
///
/// Parameter `date`: A date by which you want exclusive control acquired. If you pass +[NSDate date], control will attempt to be acquired and if it can not be, it will fail instantly.
///
/// Parameter `performHandler`: A block that will be executed once exclusive control is acquired.
/// If an error is non-nil then a problem occurred acquiring exclusive access.
///
/// # Safety
///
/// `perform_handler` block must be sendable.
#[unsafe(method(performWithExclusiveControlBeforeDate:performHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn performWithExclusiveControlBeforeDate_performHandler(
&self,
date: &NSDate,
perform_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
);
#[cfg(feature = "BADownload")]
/// Attempts to schedule a BADownload in foreground mode.
///
/// Attempts to schedule a BADownload in foreground mode. This download will start (if it has not been started) immediately regrardlesss of battery or
/// network status. The download will remain in this foreground until the download manager is disconnected. This API only functions if the download manager is created in
/// the application and not the download extension. If this API is called from the download extension, NO will be returned along with a NSError with the settings
/// BAErrorDomain : BAErrorCodeCallFromExtensionNotAllowed. If this API is called from a app while it is in the background, NO will be returned along with a NSError
/// with the settings BAErrorDomain : BAErrorCodeCallFromInactiveProcessNotAllowed.
#[unsafe(method(startForegroundDownload:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn startForegroundDownload_error(
&self,
download: &BADownload,
) -> Result<(), Retained<NSError>>;
#[cfg(feature = "BADownload")]
/// Cancels a download.
///
/// Attempts to cancel a BADownload. If the download has not been schduled or has already completed, NO is returned along with a NSError set
/// to BAErrorDomain : BAErrorCodeDownloadNotScheduled.
///
/// Returns: YES if the download is canceled. NO if the download could not be canceled,
/// `error`will be set with a reason why.
#[unsafe(method(cancelDownload:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn cancelDownload_error(
&self,
download: &BADownload,
) -> Result<(), Retained<NSError>>;
);
}