WKWebView+AFNetworking.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // WkWebView+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. #import <WebKit/WebKit.h>
  26. NS_ASSUME_NONNULL_BEGIN
  27. @class AFHTTPSessionManager;
  28. @interface WKWebView (AFNetworking)
  29. /**
  30. The session manager used to download all request
  31. */
  32. @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
  33. /**
  34. Asynchronously loads the specified request.
  35. @param request A URL request identifying the location of the content to load. This must not be `nil`.
  36. @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`.
  37. @param progress A progress object monitoring the current download progress.
  38. @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.
  39. @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.
  40. */
  41. - (void)loadRequest:(NSURLRequest *)request
  42. navigation:(WKNavigation * _Nonnull)navigation
  43. progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
  44. success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success
  45. failure:(nullable void (^)(NSError *error))failure;
  46. /**
  47. Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding.
  48. @param request A URL request identifying the location of the content to load. This must not be `nil`.
  49. @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. 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. navigation:(WKNavigation * _Nonnull)navigation
  58. MIMEType:(nullable NSString *)MIMEType
  59. textEncodingName:(nullable NSString *)textEncodingName
  60. progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
  61. success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success
  62. failure:(nullable void (^)(NSError *error))failure;
  63. @end
  64. NS_ASSUME_NONNULL_END
  65. #endif