objc2_background_assets/generated/
BADownloadManager.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_protocol!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/backgroundassets/badownloadmanagerdelegate?language=objc)
12    pub unsafe trait BADownloadManagerDelegate: NSObjectProtocol {
13        #[cfg(feature = "BADownload")]
14        /// A download has started.
15        #[optional]
16        #[unsafe(method(downloadDidBegin:))]
17        #[unsafe(method_family = none)]
18        unsafe fn downloadDidBegin(&self, download: &BADownload);
19
20        #[cfg(feature = "BADownload")]
21        /// A download has paused.
22        #[optional]
23        #[unsafe(method(downloadDidPause:))]
24        #[unsafe(method_family = none)]
25        unsafe fn downloadDidPause(&self, download: &BADownload);
26
27        #[cfg(feature = "BADownload")]
28        /// A download has made progress in bytes / total so far / total expected.
29        #[optional]
30        #[unsafe(method(download:didWriteBytes:totalBytesWritten:totalBytesExpectedToWrite:))]
31        #[unsafe(method_family = none)]
32        unsafe fn download_didWriteBytes_totalBytesWritten_totalBytesExpectedToWrite(
33            &self,
34            download: &BADownload,
35            bytes_written: i64,
36            total_bytes_written: i64,
37            total_expected_bytes: i64,
38        );
39
40        #[cfg(all(feature = "BADownload", feature = "block2"))]
41        /// A download has tried to start but gotten a challenge quest.
42        #[optional]
43        #[unsafe(method(download:didReceiveChallenge:completionHandler:))]
44        #[unsafe(method_family = none)]
45        unsafe fn download_didReceiveChallenge_completionHandler(
46            &self,
47            download: &BADownload,
48            challenge: &NSURLAuthenticationChallenge,
49            completion_handler: &block2::DynBlock<
50                dyn Fn(NSURLSessionAuthChallengeDisposition, *mut NSURLCredential),
51            >,
52        );
53
54        #[cfg(feature = "BADownload")]
55        /// A download has failed with a specific error.
56        #[optional]
57        #[unsafe(method(download:failedWithError:))]
58        #[unsafe(method_family = none)]
59        unsafe fn download_failedWithError(&self, download: &BADownload, error: &NSError);
60
61        #[cfg(feature = "BADownload")]
62        /// Download has finished.
63        ///
64        /// Parameter `fileURL`: A location to the file that has been downloaded.
65        ///
66        /// The file located at `fileURL` must be moved before this method exits scope, or it will be deleted.
67        /// It is strongly advised to move the file to its permanent destination rather than copy it.
68        ///
69        /// Warning: The file is marked by the system for deletion when the device becomes low on storage. Avoid copying or modifying
70        /// the file, as this may remove the system's ability to delete the file.
71        #[optional]
72        #[unsafe(method(download:finishedWithFileURL:))]
73        #[unsafe(method_family = none)]
74        unsafe fn download_finishedWithFileURL(&self, download: &BADownload, file_url: &NSURL);
75    }
76);
77
78extern_class!(
79    /// [Apple's documentation](https://developer.apple.com/documentation/backgroundassets/badownloadmanager?language=objc)
80    #[unsafe(super(NSObject))]
81    #[derive(Debug, PartialEq, Eq, Hash)]
82    pub struct BADownloadManager;
83);
84
85extern_conformance!(
86    unsafe impl NSObjectProtocol for BADownloadManager {}
87);
88
89impl BADownloadManager {
90    extern_methods!(
91        #[unsafe(method(init))]
92        #[unsafe(method_family = init)]
93        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
94
95        #[unsafe(method(new))]
96        #[unsafe(method_family = new)]
97        pub unsafe fn new() -> Retained<Self>;
98
99        /// Gets the singleton downloader object.
100        #[unsafe(method(sharedManager))]
101        #[unsafe(method_family = none)]
102        pub unsafe fn sharedManager() -> Retained<BADownloadManager>;
103
104        /// A object confroming to BADownloadManagerDelegate to get notified when actions occur.
105        #[unsafe(method(delegate))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn delegate(
108            &self,
109        ) -> Option<Retained<ProtocolObject<dyn BADownloadManagerDelegate>>>;
110
111        /// Setter for [`delegate`][Self::delegate].
112        ///
113        /// This is a [weak property][objc2::topics::weak_property].
114        #[unsafe(method(setDelegate:))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn setDelegate(
117            &self,
118            delegate: Option<&ProtocolObject<dyn BADownloadManagerDelegate>>,
119        );
120
121        #[cfg(feature = "BADownload")]
122        /// Fetches current downloads.
123        ///
124        /// Fetches the current list of scheduled or in-flight downloads queued by your application or extension.
125        ///
126        /// Parameter `error`: An error representing why the downloads could not be fetched.
127        ///
128        /// Returns: On success, returns a list of scheduled or in-flight downloads. On failure, returns nil and sets
129        /// `error.`
130        /// Warning: This method can block and should not be called from the main thread.
131        ///
132        /// See also: BADownloadManager:fetchCurrentDownloadsWithCompletionHandler
133        #[unsafe(method(fetchCurrentDownloads:_))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn fetchCurrentDownloads(
136            &self,
137        ) -> Result<Retained<NSArray<BADownload>>, Retained<NSError>>;
138
139        #[cfg(all(feature = "BADownload", feature = "block2"))]
140        /// Fetches current downloads.
141        ///
142        /// Fetches the current list of scheduled or in-flight downloads queued by your application or extension.
143        ///
144        /// 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.
145        ///
146        /// # Safety
147        ///
148        /// `completion_handler` block must be sendable.
149        #[unsafe(method(fetchCurrentDownloadsWithCompletionHandler:))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn fetchCurrentDownloadsWithCompletionHandler(
152            &self,
153            completion_handler: &block2::DynBlock<
154                dyn Fn(NonNull<NSArray<BADownload>>, *mut NSError),
155            >,
156        );
157
158        #[cfg(feature = "BADownload")]
159        /// Schedules a background download.
160        ///
161        /// Specifies a download to schedule at a given priority. The download will automatically
162        /// start at the discretion of the system.
163        ///
164        /// Parameter `download`: A BADownload object representing a URL to be downloaded.
165        ///
166        /// Parameter `error`: A NSError representing why the BADownload could not be scheduled.
167        ///
168        /// Returns: YES if
169        /// `download`was scheduled. NO and
170        /// `error`set if the download could not be scheduled.
171        #[unsafe(method(scheduleDownload:error:_))]
172        #[unsafe(method_family = none)]
173        pub unsafe fn scheduleDownload_error(
174            &self,
175            download: &BADownload,
176        ) -> Result<(), Retained<NSError>>;
177
178        #[cfg(feature = "block2")]
179        /// Acquires exclusive access to the BADownloadManager across the app and application extension.
180        ///
181        /// Acquires exclusive access to the BADownloadManager across the app and application extension. This ensures that your extension and app
182        /// do not perform operations at the same time. Both the extension and app must use this API to ensure exclusive access.
183        ///
184        /// Parameter `performHandler`: A block that will be executed once exclusive control is acquired.
185        /// If an error is non-nil then a problem occurred acquiring exclusive access.
186        ///
187        /// # Safety
188        ///
189        /// `perform_handler` block must be sendable.
190        #[unsafe(method(performWithExclusiveControl:))]
191        #[unsafe(method_family = none)]
192        pub unsafe fn performWithExclusiveControl(
193            &self,
194            perform_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
195        );
196
197        #[cfg(feature = "block2")]
198        /// Acquires exclusive access to the BADownloadManager across the app and application extension.
199        ///
200        /// Acquires exclusive access to the BADownloadManager across the app and application extension. This ensures that your extension and app
201        /// do not perform operations at the same time. Both the extension and app must use this API to ensure exclusive access.
202        ///
203        /// 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.
204        ///
205        /// Parameter `performHandler`: A block that will be executed once exclusive control is acquired.
206        /// If an error is non-nil then a problem occurred acquiring exclusive access.
207        ///
208        /// # Safety
209        ///
210        /// `perform_handler` block must be sendable.
211        #[unsafe(method(performWithExclusiveControlBeforeDate:performHandler:))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn performWithExclusiveControlBeforeDate_performHandler(
214            &self,
215            date: &NSDate,
216            perform_handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
217        );
218
219        #[cfg(feature = "BADownload")]
220        /// Attempts to schedule a BADownload in foreground mode.
221        ///
222        /// Attempts to schedule a BADownload in foreground mode. This download will start (if it has not been started) immediately regrardlesss of battery or
223        /// 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
224        /// 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
225        /// BAErrorDomain : BAErrorCodeCallFromExtensionNotAllowed. If this API is called from a app while it is in the background, NO will be returned along with a NSError
226        /// with the settings BAErrorDomain : BAErrorCodeCallFromInactiveProcessNotAllowed.
227        #[unsafe(method(startForegroundDownload:error:_))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn startForegroundDownload_error(
230            &self,
231            download: &BADownload,
232        ) -> Result<(), Retained<NSError>>;
233
234        #[cfg(feature = "BADownload")]
235        /// Cancels a download.
236        ///
237        /// Attempts to cancel a BADownload. If the download has not been schduled or has already completed, NO is returned along with a NSError set
238        /// to BAErrorDomain : BAErrorCodeDownloadNotScheduled.
239        ///
240        /// Returns: YES if the download is canceled. NO if the download could not be canceled,
241        /// `error`will be set with a reason why.
242        #[unsafe(method(cancelDownload:error:_))]
243        #[unsafe(method_family = none)]
244        pub unsafe fn cancelDownload_error(
245            &self,
246            download: &BADownload,
247        ) -> Result<(), Retained<NSError>>;
248    );
249}