diff --git a/AFNetworking.xcodeproj/project.pbxproj b/AFNetworking.xcodeproj/project.pbxproj index 3041f8419b..9d28f467cc 100644 --- a/AFNetworking.xcodeproj/project.pbxproj +++ b/AFNetworking.xcodeproj/project.pbxproj @@ -138,8 +138,6 @@ 299522AD1BBF13C700859F49 /* UIProgressView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 299522971BBF13C700859F49 /* UIProgressView+AFNetworking.m */; }; 299522AE1BBF13C700859F49 /* UIRefreshControl+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 299522981BBF13C700859F49 /* UIRefreshControl+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 299522AF1BBF13C700859F49 /* UIRefreshControl+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 299522991BBF13C700859F49 /* UIRefreshControl+AFNetworking.m */; }; - 299522B01BBF13C700859F49 /* UIWebView+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 2995229A1BBF13C700859F49 /* UIWebView+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 299522B11BBF13C700859F49 /* UIWebView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 2995229B1BBF13C700859F49 /* UIWebView+AFNetworking.m */; }; 29D3413F1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3413E1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m */; }; 29D341401C20D46400A7D266 /* AFCompoundResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3413E1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m */; }; 29D341411C20D46400A7D266 /* AFCompoundResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3413E1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m */; }; @@ -170,11 +168,13 @@ 29D96E981BCC406B00F571A5 /* UIImage+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 299522921BBF13C700859F49 /* UIImage+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 29D96E991BCC406B00F571A5 /* UIImageView+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 299522931BBF13C700859F49 /* UIImageView+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 29D96E9A1BCC406B00F571A5 /* UIProgressView+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 299522961BBF13C700859F49 /* UIProgressView+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 29F5EF031C47E64F008B976A /* AFUIWebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29F5EF021C47E64F008B976A /* AFUIWebViewTests.m */; }; 2D4563901DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D45638F1DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m */; }; 2D4563911DB117A200AE4812 /* AFXMLParserResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D45638F1DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m */; }; 2D4563921DB117A200AE4812 /* AFXMLParserResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D45638F1DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m */; }; 2D4563941DB11DDB00AE4812 /* AFXMLDocumentResponseSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D4563931DB11DDB00AE4812 /* AFXMLDocumentResponseSerializerTests.m */; }; + 323D83E2231D185400C5BFC6 /* WKWebView+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 323D83E0231D185400C5BFC6 /* WKWebView+AFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 323D83E3231D185400C5BFC6 /* WKWebView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 323D83E1231D185400C5BFC6 /* WKWebView+AFNetworking.m */; }; + 323D83E5231D188400C5BFC6 /* AFWKWebViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 323D83E4231D188400C5BFC6 /* AFWKWebViewTests.m */; }; 5F4323BB1BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer in Resources */ = {isa = PBXBuildFile; fileRef = 5F4323B31BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer */; }; 5F4323BC1BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer in Resources */ = {isa = PBXBuildFile; fileRef = 5F4323B31BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer */; }; 5F4323BD1BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer in Resources */ = {isa = PBXBuildFile; fileRef = 5F4323B31BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer */; }; @@ -303,12 +303,12 @@ 299522971BBF13C700859F49 /* UIProgressView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIProgressView+AFNetworking.m"; sourceTree = ""; }; 299522981BBF13C700859F49 /* UIRefreshControl+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIRefreshControl+AFNetworking.h"; sourceTree = ""; }; 299522991BBF13C700859F49 /* UIRefreshControl+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIRefreshControl+AFNetworking.m"; sourceTree = ""; }; - 2995229A1BBF13C700859F49 /* UIWebView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWebView+AFNetworking.h"; sourceTree = ""; }; - 2995229B1BBF13C700859F49 /* UIWebView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWebView+AFNetworking.m"; sourceTree = ""; }; 29D3413E1C20D46400A7D266 /* AFCompoundResponseSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFCompoundResponseSerializerTests.m; sourceTree = ""; }; - 29F5EF021C47E64F008B976A /* AFUIWebViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFUIWebViewTests.m; sourceTree = ""; }; 2D45638F1DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFXMLParserResponseSerializerTests.m; sourceTree = ""; }; 2D4563931DB11DDB00AE4812 /* AFXMLDocumentResponseSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFXMLDocumentResponseSerializerTests.m; sourceTree = ""; }; + 323D83E0231D185400C5BFC6 /* WKWebView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKWebView+AFNetworking.h"; sourceTree = ""; }; + 323D83E1231D185400C5BFC6 /* WKWebView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WKWebView+AFNetworking.m"; sourceTree = ""; }; + 323D83E4231D188400C5BFC6 /* AFWKWebViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFWKWebViewTests.m; sourceTree = ""; }; 5F4323B31BF63741003B8749 /* Equifax_Secure_Certificate_Authority_Root.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = Equifax_Secure_Certificate_Authority_Root.cer; sourceTree = ""; }; 5F4323B41BF63741003B8749 /* GeoTrust_Global_CA-cross.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = "GeoTrust_Global_CA-cross.cer"; sourceTree = ""; }; 5F4323B51BF63741003B8749 /* google.com.cer */ = {isa = PBXFileReference; lastKnownFileType = file; path = google.com.cer; sourceTree = ""; }; @@ -473,7 +473,7 @@ 298D7C8D1BC2C88F00FD3B3E /* AFUIImageViewTests.m */, 298D7C8E1BC2C88F00FD3B3E /* AFUIRefreshControlTests.m */, 2960BAC21C1B2F1A00BA02F0 /* AFUIButtonTests.m */, - 29F5EF021C47E64F008B976A /* AFUIWebViewTests.m */, + 323D83E4231D188400C5BFC6 /* AFWKWebViewTests.m */, ); name = "AFNetworking UIKit Tests"; sourceTree = ""; @@ -557,8 +557,8 @@ 299522971BBF13C700859F49 /* UIProgressView+AFNetworking.m */, 299522981BBF13C700859F49 /* UIRefreshControl+AFNetworking.h */, 299522991BBF13C700859F49 /* UIRefreshControl+AFNetworking.m */, - 2995229A1BBF13C700859F49 /* UIWebView+AFNetworking.h */, - 2995229B1BBF13C700859F49 /* UIWebView+AFNetworking.m */, + 323D83E0231D185400C5BFC6 /* WKWebView+AFNetworking.h */, + 323D83E1231D185400C5BFC6 /* WKWebView+AFNetworking.m */, ); path = "UIKit+AFNetworking"; sourceTree = ""; @@ -615,11 +615,11 @@ 299522A91BBF13C700859F49 /* UIImageView+AFNetworking.h in Headers */, 2995229E1BBF13C700859F49 /* AFImageDownloader.h in Headers */, 2995225E1BBF125A00859F49 /* AFURLSessionManager.h in Headers */, + 323D83E2231D185400C5BFC6 /* WKWebView+AFNetworking.h in Headers */, 2995225C1BBF125A00859F49 /* AFURLResponseSerialization.h in Headers */, 299522A21BBF13C700859F49 /* UIActivityIndicatorView+AFNetworking.h in Headers */, 1F96D2A4203649560085FC3F /* AFCompatibilityMacros.h in Headers */, 2995223D1BBF104D00859F49 /* AFNetworking.h in Headers */, - 299522B01BBF13C700859F49 /* UIWebView+AFNetworking.h in Headers */, 299522AC1BBF13C700859F49 /* UIProgressView+AFNetworking.h in Headers */, 299522A61BBF13C700859F49 /* UIButton+AFNetworking.h in Headers */, 299522A01BBF13C700859F49 /* AFNetworkActivityIndicatorManager.h in Headers */, @@ -824,6 +824,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 2995222F1BBF104D00859F49; @@ -1017,8 +1018,8 @@ 298D7CD91BC2CAF200FD3B3E /* AFNetworkReachabilityManagerTests.m in Sources */, 297824AA1BC2DAD80041C395 /* AFAutoPurgingImageCacheTests.m in Sources */, 298D7C981BC2CA2500FD3B3E /* AFURLSessionManagerTests.m in Sources */, + 323D83E5231D188400C5BFC6 /* AFWKWebViewTests.m in Sources */, 297824AC1BC2DB450041C395 /* AFImageDownloaderTests.m in Sources */, - 29F5EF031C47E64F008B976A /* AFUIWebViewTests.m in Sources */, 2D4563901DB1179D00AE4812 /* AFXMLParserResponseSerializerTests.m in Sources */, 298D7CD51BC2CAEC00FD3B3E /* AFHTTPSessionManagerTests.m in Sources */, 298D7CD71BC2CAEF00FD3B3E /* AFJSONSerializationTests.m in Sources */, @@ -1055,10 +1056,10 @@ 299522571BBF125A00859F49 /* AFNetworkReachabilityManager.m in Sources */, 299522AF1BBF13C700859F49 /* UIRefreshControl+AFNetworking.m in Sources */, 299522AA1BBF13C700859F49 /* UIImageView+AFNetworking.m in Sources */, - 299522B11BBF13C700859F49 /* UIWebView+AFNetworking.m in Sources */, 299522591BBF125A00859F49 /* AFSecurityPolicy.m in Sources */, 299522A71BBF13C700859F49 /* UIButton+AFNetworking.m in Sources */, 299522541BBF125A00859F49 /* AFHTTPSessionManager.m in Sources */, + 323D83E3231D185400C5BFC6 /* WKWebView+AFNetworking.m in Sources */, 2995225F1BBF125A00859F49 /* AFURLSessionManager.m in Sources */, 2995225B1BBF125A00859F49 /* AFURLRequestSerialization.m in Sources */, 2995229D1BBF13C700859F49 /* AFAutoPurgingImageCache.m in Sources */, diff --git a/Framework/AFNetworking.h b/Framework/AFNetworking.h index b8edcfdecd..1c8f595727 100644 --- a/Framework/AFNetworking.h +++ b/Framework/AFNetworking.h @@ -60,7 +60,7 @@ FOUNDATION_EXPORT const unsigned char AFNetworkingVersionString[]; #if TARGET_OS_IOS #import #import -#import +#import #endif diff --git a/Tests/Tests/AFUIWebViewTests.m b/Tests/Tests/AFWKWebViewTests.m similarity index 51% rename from Tests/Tests/AFUIWebViewTests.m rename to Tests/Tests/AFWKWebViewTests.m index 92a906e43a..80c10b56d4 100644 --- a/Tests/Tests/AFUIWebViewTests.m +++ b/Tests/Tests/AFWKWebViewTests.m @@ -1,4 +1,4 @@ -// AFUIWebViewTests.h +// AFWKWebViewTests.m // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -20,85 +20,117 @@ // THE SOFTWARE. #import +#import #import "AFTestCase.h" -#import "UIWebView+AFNetworking.h" +#import "WKWebView+AFNetworking.h" -@interface AFUIWebViewTests : AFTestCase +@interface AFWKWebViewTests : AFTestCase -@property (nonatomic, strong) UIWebView *webView; +@property (nonatomic, strong) WKWebView *webView; +@property (nonatomic, strong) WKNavigation *navigation; @property (nonatomic, strong) NSURLRequest *HTMLRequest; +@property (nonatomic, strong) NSURLRequest *largeHTMLRequest; +@property (nonatomic, strong) NSURLRequest *headerRequest; +@property (nonatomic, strong) NSProgress *progressCapture; @end -@implementation AFUIWebViewTests +@implementation AFWKWebViewTests -- (void)setUp { +-(void)setUp { [super setUp]; - self.webView = [UIWebView new]; - self.HTMLRequest = [NSURLRequest requestWithURL:[self.baseURL URLByAppendingPathComponent:@"html"]]; + self.webView = [WKWebView new]; + self.webView.navigationDelegate = self; + self.navigation = [WKNavigation new]; + self.HTMLRequest = [NSURLRequest requestWithURL:[self.baseURL URLByAppendingPathComponent:@"html"] + cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData + timeoutInterval:self.networkTimeout]; + NSURL * largeURL = [[self.baseURL URLByAppendingPathComponent:@"bytes"] URLByAppendingPathComponent:@(1024 * 1024).stringValue]; + self.largeHTMLRequest = [NSURLRequest requestWithURL:largeURL + cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData + timeoutInterval:self.networkTimeout]; + NSMutableURLRequest *customHeaderRequest = [NSMutableURLRequest requestWithURL:[self.baseURL URLByAppendingPathComponent:@"headers"]]; + [customHeaderRequest setValue:@"Custom-Header-Value" forHTTPHeaderField:@"Custom-Header-Field"]; + self.headerRequest = customHeaderRequest; } - (void)testNilProgressDoesNotCauseCrash { XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; [self.webView loadRequest:self.HTMLRequest + navigation:self.navigation progress:nil success:^NSString * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSString * _Nonnull HTML) { [expectation fulfill]; return HTML; - } - failure:nil]; + } failure:^(NSError * _Nonnull error) { + XCTFail(@"Request %@ failed with error %@", self.HTMLRequest, error); + [expectation fulfill]; + }]; [self waitForExpectationsWithCommonTimeout]; } -- (void)testNULLProgressDoesNotCauseCrash { +- (void)testNUllProgressDoesNotCauseCrash { XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; [self.webView loadRequest:self.HTMLRequest + navigation:self.navigation progress:NULL success:^NSString * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSString * _Nonnull HTML) { [expectation fulfill]; return HTML; - } - failure:nil]; + } failure:^(NSError * _Nonnull error) { + XCTFail(@"Request %@ failed with error %@", self.HTMLRequest, error); + [expectation fulfill]; + }]; [self waitForExpectationsWithCommonTimeout]; } -//- (void)testProgressIsSet { -// NSProgress* progress = nil; -// XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; -// [self.webView -// loadRequest:self.HTMLRequest -// progress:&progress -// success:^NSString * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSString * _Nonnull HTML) { -// [expectation fulfill]; -// return HTML; -// } -// failure:nil]; -// [self keyValueObservingExpectationForObject:progress -// keyPath:@"fractionCompleted" -// expectedValue:@(1.0)]; -// [self waitForExpectationsWithCommonTimeout]; -//} +- (void)testProgressIsSet { + NSProgress* progress = nil; + XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; + + [self.webView + loadRequest:self.largeHTMLRequest + navigation:self.navigation + progress:&progress + success:^NSString * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSString * _Nonnull HTML) { + [expectation fulfill]; + return HTML; + } failure:^(NSError * _Nonnull error) { + XCTFail(@"Request %@ failed with error %@", self.largeHTMLRequest, error); + [expectation fulfill]; + }]; + [self keyValueObservingExpectationForObject:progress + keyPath:@"fractionCompleted" + expectedValue:@(1.0)]; + [self waitForExpectationsWithCommonTimeout]; +} - (void)testRequestWithCustomHeaders { - NSMutableURLRequest *customHeaderRequest = [NSMutableURLRequest requestWithURL:[self.baseURL URLByAppendingPathComponent:@"headers"]]; - [customHeaderRequest setValue:@"Custom-Header-Value" forHTTPHeaderField:@"Custom-Header-Field"]; + XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"]; [self.webView - loadRequest:customHeaderRequest + loadRequest:self.headerRequest + navigation:self.navigation progress:NULL success:^NSString * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSString * _Nonnull string) { - // Here string is actually JSON. + // Here string is actually JSON NSDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:(NSJSONReadingOptions)0 error:nil]; NSDictionary *headers = responseObject[@"headers"]; XCTAssertTrue([headers[@"Custom-Header-Field"] isEqualToString:@"Custom-Header-Value"]); [expectation fulfill]; return string; - } - failure:nil]; + } failure:^(NSError * _Nonnull error) { + XCTFail(@"Request %@ failed with error %@", self.headerRequest, error); + [expectation fulfill]; + }]; [self waitForExpectationsWithCommonTimeout]; } +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { + XCTFail(@"Navigation failed with error %@", error); +} + @end diff --git a/UIKit+AFNetworking/UIKit+AFNetworking.h b/UIKit+AFNetworking/UIKit+AFNetworking.h index febacfc755..5d57e1d697 100644 --- a/UIKit+AFNetworking/UIKit+AFNetworking.h +++ b/UIKit+AFNetworking/UIKit+AFNetworking.h @@ -31,7 +31,7 @@ #import "AFImageDownloader.h" #import "AFNetworkActivityIndicatorManager.h" #import "UIRefreshControl+AFNetworking.h" - #import "UIWebView+AFNetworking.h" + #import "WKWebView+AFNetworking.h" #endif #import "UIActivityIndicatorView+AFNetworking.h" diff --git a/UIKit+AFNetworking/UIWebView+AFNetworking.h b/UIKit+AFNetworking/WKWebView+AFNetworking.h similarity index 83% rename from UIKit+AFNetworking/UIWebView+AFNetworking.h rename to UIKit+AFNetworking/WKWebView+AFNetworking.h index b9a56af4bf..680fedff80 100644 --- a/UIKit+AFNetworking/UIWebView+AFNetworking.h +++ b/UIKit+AFNetworking/WKWebView+AFNetworking.h @@ -1,4 +1,4 @@ -// UIWebView+AFNetworking.h +// WkWebView+AFNetworking.h // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -26,47 +26,47 @@ #if TARGET_OS_IOS #import +#import NS_ASSUME_NONNULL_BEGIN @class AFHTTPSessionManager; -/** - 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. - - @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. - */ -@interface UIWebView (AFNetworking) +@interface WKWebView (AFNetworking) /** - The session manager used to download all requests. + The session manager used to download all request */ @property (nonatomic, strong) AFHTTPSessionManager *sessionManager; /** Asynchronously loads the specified request. - + @param request A URL request identifying the location of the content to load. This must not be `nil`. + @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`. @param progress A progress object monitoring the current download progress. @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. @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. */ - (void)loadRequest:(NSURLRequest *)request + navigation:(WKNavigation * _Nonnull)navigation progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success failure:(nullable void (^)(NSError *error))failure; /** Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding. - + @param request A URL request identifying the location of the content to load. This must not be `nil`. + @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`. @param MIMEType The MIME type of the content. Defaults to the content type of the response if not specified. @param textEncodingName The IANA encoding name, as in `utf-8` or `utf-16`. Defaults to the response text encoding if not specified. -@param progress A progress object monitoring the current download progress. + @param progress A progress object monitoring the current download progress. @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. @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. */ - (void)loadRequest:(NSURLRequest *)request + navigation:(WKNavigation * _Nonnull)navigation MIMEType:(nullable NSString *)MIMEType textEncodingName:(nullable NSString *)textEncodingName progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress diff --git a/UIKit+AFNetworking/UIWebView+AFNetworking.m b/UIKit+AFNetworking/WKWebView+AFNetworking.m similarity index 69% rename from UIKit+AFNetworking/UIWebView+AFNetworking.m rename to UIKit+AFNetworking/WKWebView+AFNetworking.m index b760314f57..6eca3c3a54 100644 --- a/UIKit+AFNetworking/UIWebView+AFNetworking.m +++ b/UIKit+AFNetworking/WKWebView+AFNetworking.m @@ -1,4 +1,4 @@ -// UIWebView+AFNetworking.m +// WkWebView+AFNetworking.m // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -19,7 +19,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "UIWebView+AFNetworking.h" +#import "WKWebView+AFNetworking.h" #import @@ -29,11 +29,11 @@ #import "AFURLResponseSerialization.h" #import "AFURLRequestSerialization.h" -@interface UIWebView (_AFNetworking) +@interface WKWebView (_AFNetworking) @property (readwrite, nonatomic, strong, setter = af_setURLSessionTask:) NSURLSessionDataTask *af_URLSessionTask; @end -@implementation UIWebView (_AFNetworking) +@implementation WKWebView (_AFNetworking) - (NSURLSessionDataTask *)af_URLSessionTask { return (NSURLSessionDataTask *)objc_getAssociatedObject(self, @selector(af_URLSessionTask)); @@ -47,7 +47,7 @@ - (void)af_setURLSessionTask:(NSURLSessionDataTask *)af_URLSessionTask { #pragma mark - -@implementation UIWebView (AFNetworking) +@implementation WKWebView (AFNetworking) - (AFHTTPSessionManager *)sessionManager { static AFHTTPSessionManager *_af_defaultHTTPSessionManager = nil; @@ -57,7 +57,7 @@ - (AFHTTPSessionManager *)sessionManager { _af_defaultHTTPSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; _af_defaultHTTPSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; }); - + return objc_getAssociatedObject(self, @selector(sessionManager)) ?: _af_defaultHTTPSessionManager; } @@ -71,7 +71,7 @@ - (void)setSessionManager:(AFHTTPSessionManager *)sessionManager { dispatch_once(&onceToken, ^{ _af_defaultResponseSerializer = [AFHTTPResponseSerializer serializer]; }); - + return objc_getAssociatedObject(self, @selector(responseSerializer)) ?: _af_defaultResponseSerializer; } @@ -82,11 +82,11 @@ - (void)setResponseSerializer:(AFHTTPResponseSerializer