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