objc2_foundation/generated/
NSURLDownload.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::*;
6
7use crate::*;
8
9extern_class!(
10    /// A NSURLDownload loads a request and saves the downloaded data to a file. The progress of the download
11    /// is reported via the NSURLDownloadDelegate protocol. Note: The word "download" is used to refer to the process
12    /// of loading data off a network, decoding the data if necessary and saving the data to a file.
13    ///
14    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurldownload?language=objc)
15    #[unsafe(super(NSObject))]
16    #[derive(Debug, PartialEq, Eq, Hash)]
17    pub struct NSURLDownload;
18);
19
20extern_conformance!(
21    unsafe impl NSObjectProtocol for NSURLDownload {}
22);
23
24impl NSURLDownload {
25    extern_methods!(
26        #[cfg(feature = "NSString")]
27        /// Returns whether or not NSURLDownload can resume a download that was decoded with a given encoding MIME type.
28        ///
29        /// Parameter `MIMEType`: The encoding MIME type.
30        /// canResumeDownloadDecodedWithEncodingMIMEType: returns whether or not NSURLDownload can resume a download
31        /// that was decoded with a given encoding MIME type.  NSURLDownload cannot resume a download that was partially decoded
32        /// in the gzip format for example. In order to ensure that a download can be later resumed,
33        /// canResumeDownloadDecodedWithEncodingMIMEType: should be used when download:shouldDecodeSourceDataOfMIMEType: is called.
34        #[unsafe(method(canResumeDownloadDecodedWithEncodingMIMEType:))]
35        #[unsafe(method_family = none)]
36        pub unsafe fn canResumeDownloadDecodedWithEncodingMIMEType(mime_type: &NSString) -> bool;
37
38        #[cfg(feature = "NSURLRequest")]
39        /// Initializes a NSURLDownload object and starts the download.
40        ///
41        /// Parameter `request`: The request to download. Must not be nil.
42        ///
43        /// Parameter `delegate`: The delegate of the download.
44        ///
45        /// Returns: An initialized NSURLDownload object.
46        #[deprecated = "Use NSURLSession downloadTask (see NSURLSession.h)"]
47        #[unsafe(method(initWithRequest:delegate:))]
48        #[unsafe(method_family = init)]
49        pub unsafe fn initWithRequest_delegate(
50            this: Allocated<Self>,
51            request: &NSURLRequest,
52            delegate: Option<&ProtocolObject<dyn NSURLDownloadDelegate>>,
53        ) -> Retained<Self>;
54
55        #[cfg(all(feature = "NSData", feature = "NSString"))]
56        /// Initializes a NSURLDownload object for resuming a previous download.
57        ///
58        /// Parameter `resumeData`: The resume data from the previous download.
59        ///
60        /// Parameter `delegate`: The delegate of the download.
61        ///
62        /// Parameter `path`: The path of the incomplete downloaded file.
63        ///
64        /// Returns: An initialized NSURLDownload object.
65        #[deprecated = "Use NSURLSession downloadTask (see NSURLSession.h)"]
66        #[unsafe(method(initWithResumeData:delegate:path:))]
67        #[unsafe(method_family = init)]
68        pub unsafe fn initWithResumeData_delegate_path(
69            this: Allocated<Self>,
70            resume_data: &NSData,
71            delegate: Option<&ProtocolObject<dyn NSURLDownloadDelegate>>,
72            path: &NSString,
73        ) -> Retained<Self>;
74
75        /// Cancels the download and deletes the downloaded file.
76        #[unsafe(method(cancel))]
77        #[unsafe(method_family = none)]
78        pub unsafe fn cancel(&self);
79
80        #[cfg(feature = "NSString")]
81        /// Sets the destination path of the downloaded file.
82        ///
83        /// Parameter `path`: The destination path of the downloaded file.
84        ///
85        /// Parameter `allowOverwrite`: Allows a file of the same path to be overwritten.
86        ///
87        /// This method can be called after the download is created or in response to the
88        /// decideDestinationWithSuggestedFilename: delegate method. It should only be called once.
89        /// If NO is passed for allowOverwrite and a file of the same path exists, a number will be
90        /// appended to the filename to prevent the overwrite. Because of this, use the path
91        /// passed with didCreateDestination: to determine the actual path of the downloaded file.
92        #[unsafe(method(setDestination:allowOverwrite:))]
93        #[unsafe(method_family = none)]
94        pub unsafe fn setDestination_allowOverwrite(&self, path: &NSString, allow_overwrite: bool);
95
96        #[cfg(feature = "NSURLRequest")]
97        /// Returns the request of the download.
98        ///
99        /// Returns: The request of the download.
100        #[unsafe(method(request))]
101        #[unsafe(method_family = none)]
102        pub unsafe fn request(&self) -> Retained<NSURLRequest>;
103
104        #[cfg(feature = "NSData")]
105        /// Returns the resume data of a download that is incomplete.
106        ///
107        /// Returns: The resume data.
108        /// resumeData returns the resume data of a download that is incomplete. This data represents the necessary
109        /// state information that NSURLDownload needs to resume a download. The resume data can later be used when initializing
110        /// a download with initWithResumeData:delegate:path:. Non-nil is returned if resuming the download seems possible.
111        /// Non-nil is returned if the download was cancelled or ended in error after some but not all data has been received.
112        /// The protocol of the download as well as the server must support resuming for non-nil to be returned.
113        /// In order to later resume a download, be sure to call setDeletesFileUponFailure: with NO.
114        #[unsafe(method(resumeData))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn resumeData(&self) -> Option<Retained<NSData>>;
117
118        /// Sets whether or not the downloaded file should be deleted upon failure.
119        /// 1
120        /// To allow the download to be resumed in case the download ends prematurely,
121        /// deletesFileUponFailure must be set to NO as soon as possible to prevent the downloaded file
122        /// from being deleted. deletesFileUponFailure is YES by default.
123        #[unsafe(method(deletesFileUponFailure))]
124        #[unsafe(method_family = none)]
125        pub unsafe fn deletesFileUponFailure(&self) -> bool;
126
127        /// Setter for [`deletesFileUponFailure`][Self::deletesFileUponFailure].
128        #[unsafe(method(setDeletesFileUponFailure:))]
129        #[unsafe(method_family = none)]
130        pub unsafe fn setDeletesFileUponFailure(&self, deletes_file_upon_failure: bool);
131    );
132}
133
134/// Methods declared on superclass `NSObject`.
135impl NSURLDownload {
136    extern_methods!(
137        #[unsafe(method(init))]
138        #[unsafe(method_family = init)]
139        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
140
141        #[unsafe(method(new))]
142        #[unsafe(method_family = new)]
143        pub unsafe fn new() -> Retained<Self>;
144    );
145}
146
147extern_protocol!(
148    /// The NSURLDownloadDelegate delegate is used to report the progress of the download.
149    ///
150    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurldownloaddelegate?language=objc)
151    pub unsafe trait NSURLDownloadDelegate: NSObjectProtocol {
152        /// This method is called immediately after the download has started.
153        ///
154        /// Parameter `download`: The download that just started downloading.
155        #[optional]
156        #[unsafe(method(downloadDidBegin:))]
157        #[unsafe(method_family = none)]
158        unsafe fn downloadDidBegin(&self, download: &NSURLDownload);
159
160        #[cfg(all(feature = "NSURLRequest", feature = "NSURLResponse"))]
161        /// This method is called if the download must load another request because the previous
162        /// request was redirected.
163        ///
164        /// Parameter `download`: The download that will send the request.
165        ///
166        /// Parameter `request`: The request that will be used to continue loading.
167        ///
168        /// Returns: The request to be used; either the request parameter or a replacement. If nil is returned,
169        /// the download is cancelled.
170        ///
171        /// This method gives the delegate an opportunity to inspect the request
172        /// that will be used to continue loading the request, and modify it if necessary.
173        #[optional]
174        #[unsafe(method(download:willSendRequest:redirectResponse:))]
175        #[unsafe(method_family = none)]
176        unsafe fn download_willSendRequest_redirectResponse(
177            &self,
178            download: &NSURLDownload,
179            request: &NSURLRequest,
180            redirect_response: Option<&NSURLResponse>,
181        ) -> Option<Retained<NSURLRequest>>;
182
183        #[cfg(feature = "NSURLProtectionSpace")]
184        /// This method gives the delegate an opportunity to inspect an NSURLProtectionSpace before an authentication attempt is made.
185        ///
186        /// If implemented, will be called before connection:didReceiveAuthenticationChallenge
187        /// to give the delegate a chance to inspect the protection space that will be authenticated against.  Delegates should determine
188        /// if they are prepared to respond to the authentication method of the protection space and if so, return YES, or NO to
189        /// allow default processing to handle the authentication.  If this delegate is not implemented, then default
190        /// processing will occur (typically, consulting
191        /// the user's keychain and/or failing the connection attempt.
192        ///
193        /// Parameter `connection`: an NSURLConnection that has an NSURLProtectionSpace ready for inspection
194        ///
195        /// Parameter `protectionSpace`: an NSURLProtectionSpace that will be used to generate an authentication challenge
196        ///
197        /// Returns: a boolean value that indicates the willingness of the delegate to handle the authentication
198        #[optional]
199        #[unsafe(method(download:canAuthenticateAgainstProtectionSpace:))]
200        #[unsafe(method_family = none)]
201        unsafe fn download_canAuthenticateAgainstProtectionSpace(
202            &self,
203            connection: &NSURLDownload,
204            protection_space: &NSURLProtectionSpace,
205        ) -> bool;
206
207        #[cfg(feature = "NSURLAuthenticationChallenge")]
208        /// Start authentication for a given challenge
209        ///
210        /// Parameter `download`: The download that needs authentication.
211        ///
212        /// Parameter `challenge`: The NSURLAuthenticationChallenge for which to start authentication.
213        ///
214        /// Call useCredential:forAuthenticationChallenge:,
215        /// continueWithoutCredentialForAuthenticationChallenge: or cancel on
216        /// the connection sender when done.
217        #[optional]
218        #[unsafe(method(download:didReceiveAuthenticationChallenge:))]
219        #[unsafe(method_family = none)]
220        unsafe fn download_didReceiveAuthenticationChallenge(
221            &self,
222            download: &NSURLDownload,
223            challenge: &NSURLAuthenticationChallenge,
224        );
225
226        #[cfg(feature = "NSURLAuthenticationChallenge")]
227        /// Cancel authentication for a given request
228        ///
229        /// Parameter `download`: The download that's cancelling
230        ///
231        /// Parameter `challenge`: The NSURLAuthenticationChallenge to cancel authentication for
232        #[optional]
233        #[unsafe(method(download:didCancelAuthenticationChallenge:))]
234        #[unsafe(method_family = none)]
235        unsafe fn download_didCancelAuthenticationChallenge(
236            &self,
237            download: &NSURLDownload,
238            challenge: &NSURLAuthenticationChallenge,
239        );
240
241        /// This method allows the delegate to inform the url loader that it
242        /// should not consult the credential storage for the download.
243        ///
244        /// This method will be called before any attempt to authenticate is
245        /// attempted on a download.  By returning NO the delegate is telling the
246        /// download to not consult the credential storage and taking responsibility
247        /// for providing any credentials for authentication challenges.  Not implementing
248        /// this method is the same as returning YES.  The delegate is free to consult the
249        /// credential storage itself when it receives a didReceiveAuthenticationChallenge
250        /// message.
251        ///
252        /// Parameter `download`: the NSURLDownload object asking if it should consult the credential storage.
253        ///
254        /// Returns: NO if the download should not consult the credential storage, Yes if it should.
255        #[optional]
256        #[unsafe(method(downloadShouldUseCredentialStorage:))]
257        #[unsafe(method_family = none)]
258        unsafe fn downloadShouldUseCredentialStorage(&self, download: &NSURLDownload) -> bool;
259
260        #[cfg(feature = "NSURLResponse")]
261        /// This method is called when the download has received a response from the server.
262        ///
263        /// Parameter `download`: The download that now has a NSURLResponse available for inspection.
264        ///
265        /// Parameter `response`: The NSURLResponse object for the given download.
266        ///
267        /// In some rare cases, multiple responses may be received for a single download.
268        /// This occurs with multipart/x-mixed-replace, or "server push". In this case, the client
269        /// should assume that each new response resets progress so far for the resource back to 0,
270        /// and should check the new response for the expected content length.
271        #[optional]
272        #[unsafe(method(download:didReceiveResponse:))]
273        #[unsafe(method_family = none)]
274        unsafe fn download_didReceiveResponse(
275            &self,
276            download: &NSURLDownload,
277            response: &NSURLResponse,
278        );
279
280        #[cfg(feature = "NSURLResponse")]
281        /// This method is called when the download has received a response from the server after attempting to
282        /// resume a download.
283        ///
284        /// Parameter `download`: The download that now has a NSURLResponse available for inspection.
285        ///
286        /// Parameter `response`: The NSURLResponse object for the given download.
287        ///
288        /// Parameter `startingByte`: The number of bytes from where the download will resume. 0 indicates that the download will
289        /// restart from the beginning.
290        ///
291        /// download:willResumeWithResponse:fromByte: is called instead of download:didReceiveResponse:
292        /// when a download is initialized with initWithResumeData:delegate:path:.
293        #[optional]
294        #[unsafe(method(download:willResumeWithResponse:fromByte:))]
295        #[unsafe(method_family = none)]
296        unsafe fn download_willResumeWithResponse_fromByte(
297            &self,
298            download: &NSURLDownload,
299            response: &NSURLResponse,
300            starting_byte: c_longlong,
301        );
302
303        /// This method is called when the download has loaded data.
304        ///
305        /// Parameter `download`: The download that has received data.
306        ///
307        /// Parameter `length`: The length of the received data.
308        ///
309        /// This method will be called one or more times.
310        #[optional]
311        #[unsafe(method(download:didReceiveDataOfLength:))]
312        #[unsafe(method_family = none)]
313        unsafe fn download_didReceiveDataOfLength(
314            &self,
315            download: &NSURLDownload,
316            length: NSUInteger,
317        );
318
319        #[cfg(feature = "NSString")]
320        /// This method is called if the download detects that the downloading file is encoded.
321        ///
322        /// Parameter `download`: The download that has detected that the downloading file is encoded.
323        ///
324        /// Parameter `encodingType`: A MIME type expressing the encoding type.
325        ///
326        /// Returns: Return YES to decode the file, NO to not decode the file.
327        ///
328        /// An encoded file is encoded in MacBinary, BinHex or gzip format. This method may be
329        /// called more than once if the file is encoded multiple times. This method is not called if the
330        /// download is not encoded.
331        #[optional]
332        #[unsafe(method(download:shouldDecodeSourceDataOfMIMEType:))]
333        #[unsafe(method_family = none)]
334        unsafe fn download_shouldDecodeSourceDataOfMIMEType(
335            &self,
336            download: &NSURLDownload,
337            encoding_type: &NSString,
338        ) -> bool;
339
340        #[cfg(feature = "NSString")]
341        /// This method is called when enough information has been loaded to decide a destination
342        /// for the downloaded file.
343        ///
344        /// Parameter `download`: The download that requests the download path.
345        ///
346        /// Parameter `filename`: The suggested filename for deciding the path of the downloaded file. The filename is either
347        /// derived from the last path component of the URL and the MIME type or if the download was encoded,
348        /// it is the filename specified in the encoding.
349        ///
350        /// Once the delegate has decided a path, it should call setDestination:allowOverwrite:.
351        /// The delegate may respond immediately or later. This method is not called if
352        /// setDestination:allowOverwrite: has already been called.
353        #[optional]
354        #[unsafe(method(download:decideDestinationWithSuggestedFilename:))]
355        #[unsafe(method_family = none)]
356        unsafe fn download_decideDestinationWithSuggestedFilename(
357            &self,
358            download: &NSURLDownload,
359            filename: &NSString,
360        );
361
362        #[cfg(feature = "NSString")]
363        /// This method is called after the download creates the downloaded file.
364        ///
365        /// Parameter `download`: The download that created the downloaded file.
366        ///
367        /// Parameter `path`: The path of the downloaded file.
368        #[optional]
369        #[unsafe(method(download:didCreateDestination:))]
370        #[unsafe(method_family = none)]
371        unsafe fn download_didCreateDestination(&self, download: &NSURLDownload, path: &NSString);
372
373        /// This method is called when the download has finished downloading.
374        ///
375        /// Parameter `download`: The download that has finished downloading.
376        ///
377        /// This method is called after all the data has been received and written to disk.
378        /// This method or download:didFailWithError: will only be called once.
379        #[optional]
380        #[unsafe(method(downloadDidFinish:))]
381        #[unsafe(method_family = none)]
382        unsafe fn downloadDidFinish(&self, download: &NSURLDownload);
383
384        #[cfg(feature = "NSError")]
385        /// This method is called when the download has failed.
386        ///
387        /// Parameter `download`: The download that ended in error.
388        ///
389        /// Parameter `error`: The error caused the download to fail.
390        ///
391        /// This method is called when the download encounters a network or file I/O related error.
392        /// This method or downloadDidFinish: will only be called once.
393        #[optional]
394        #[unsafe(method(download:didFailWithError:))]
395        #[unsafe(method_family = none)]
396        unsafe fn download_didFailWithError(&self, download: &NSURLDownload, error: &NSError);
397    }
398);