Brak opisu

UIWebView+AFNetworking.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // UIWebView+AFNetworking.h
  2. // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. #import <Foundation/Foundation.h>
  22. #import <TargetConditionals.h>
  23. #if TARGET_OS_IOS
  24. #import <UIKit/UIKit.h>
  25. NS_ASSUME_NONNULL_BEGIN
  26. @class AFHTTPSessionManager;
  27. /**
  28. This category adds methods to the UIKit framework's `UIWebView` class. The methods in this category provide increased control over the request cycle, including progress monitoring and success / failure handling.
  29. @discussion When using these category methods, make sure to assign `delegate` for the web view, which implements `–webView:shouldStartLoadWithRequest:navigationType:` appropriately. This allows for tapped links to be loaded through AFNetworking, and can ensure that `canGoBack` & `canGoForward` update their values correctly.
  30. */
  31. @interface UIWebView (AFNetworking)
  32. /**
  33. The session manager used to download all requests.
  34. */
  35. @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
  36. /**
  37. Asynchronously loads the specified request.
  38. @param request A URL request identifying the location of the content to load. This must not be `nil`.
  39. @param progress A progress object monitoring the current download progress.
  40. @param success A block object to be executed when the request finishes loading successfully. This block returns the HTML string to be loaded by the web view, and takes two arguments: the response, and the response string.
  41. @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
  42. */
  43. - (void)loadRequest:(NSURLRequest *)request
  44. progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
  45. success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success
  46. failure:(nullable void (^)(NSError *error))failure;
  47. /**
  48. Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding.
  49. @param request A URL request identifying the location of the content to load. This must not be `nil`.
  50. @param MIMEType The MIME type of the content. Defaults to the content type of the response if not specified.
  51. @param textEncodingName The IANA encoding name, as in `utf-8` or `utf-16`. Defaults to the response text encoding if not specified.
  52. @param progress A progress object monitoring the current download progress.
  53. @param success A block object to be executed when the request finishes loading successfully. This block returns the data to be loaded by the web view and takes two arguments: the response, and the downloaded data.
  54. @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
  55. */
  56. - (void)loadRequest:(NSURLRequest *)request
  57. MIMEType:(nullable NSString *)MIMEType
  58. textEncodingName:(nullable NSString *)textEncodingName
  59. progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
  60. success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success
  61. failure:(nullable void (^)(NSError *error))failure;
  62. @end
  63. NS_ASSUME_NONNULL_END
  64. #endif