URLDownloader.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // URLDownloader.h
  3. // iOS-URLDownloader
  4. //
  5. // Created by Kristijan Sedlak on 7/21/11.
  6. // Copyright 2011 AppStrides. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "URLCredential.h"
  10. @class URLDownloader;
  11. #pragma mark -
  12. typedef enum
  13. {
  14. URLDownloaderStateInactive = 0,
  15. URLDownloaderStateConnecting = 1,
  16. URLDownloaderStateAuthenticating = 2,
  17. URLDownloaderStateStarted = 3,
  18. URLDownloaderStateDownloading = 4,
  19. URLDownloaderStateFinished = 5,
  20. URLDownloaderStateCanceled = 6
  21. }
  22. URLDownloaderState;
  23. #pragma mark -
  24. @protocol URLDownloaderDelegate <NSObject>
  25. @required
  26. - (void)urlDownloader:(URLDownloader *)urlDownloader didFinishWithData:(NSData *)data;
  27. - (void)urlDownloader:(URLDownloader *)urlDownloader didFailOnAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
  28. - (void)urlDownloader:(URLDownloader *)urlDownloader didFailWithError:(NSError *)error;
  29. - (void)urlDownloader:(URLDownloader *)urlDownloader didFailWithNotConnectedToInternetError:(NSError *)error;
  30. @optional
  31. - (void)urlDownloaderDidStart:(URLDownloader *)urlDownloader;
  32. - (void)urlDownloaderDidCancelDownloading:(URLDownloader *)urlDownloader;
  33. - (void)urlDownloader:(URLDownloader *)urlDownloader didReceiveData:(NSData *)data;
  34. - (void)urlDownloader:(URLDownloader *)urlDownloader didChangeStateTo:(URLDownloaderState)state;
  35. @end
  36. #pragma mark -
  37. @interface URLDownloader : NSObject
  38. {
  39. id <URLDownloaderDelegate> delegate;
  40. NSURLConnection *urlConnection;
  41. NSURLResponse *urlResponse;
  42. NSMutableData *urlData;
  43. URLCredential *urlCredential;
  44. URLDownloaderState state;
  45. float bytesReceived;
  46. }
  47. @property(retain) id <URLDownloaderDelegate> delegate;
  48. @property(nonatomic, readonly) URLDownloaderState state;
  49. @property (strong, atomic) void (^CompletedBlock)(NSString *downloadedFile);
  50. typedef void(^DownloadCompletedBlock)(NSString *downloadedFile);
  51. @property (nonatomic, retain) NSString *downloadLocation;
  52. - (void)downloadFileWithURL:(NSURL *)url
  53. toLocation:(NSString *)dlLocation
  54. withCredential:(URLCredential *)credential
  55. completed:(DownloadCompletedBlock)completedBlock;
  56. + (id)downloaderWithDelegate:(id)obj;
  57. - (id)initWithDelegate:(id)obj;
  58. - (void)download:(NSURLRequest *)request withCredential:(URLCredential *)credential;
  59. - (void)cancel;
  60. - (int)fullContentSize;
  61. - (int)downloadedContentSize;
  62. - (float)downloadCompleteProcent;
  63. @end