Skip to content

Commit

Permalink
replacing AFNewtworking file and classes names to prevent conflicts w…
Browse files Browse the repository at this point in the history
…ith the real AFNetworking pod
  • Loading branch information
meiramar committed Jul 25, 2021
1 parent 0ccf64e commit c2a0317
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 268 deletions.
26 changes: 13 additions & 13 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@
<header-file src="src/ios/BinaryResponseSerializer.h"/>
<header-file src="src/ios/TextResponseSerializer.h"/>
<header-file src="src/ios/TextRequestSerializer.h"/>
<header-file src="src/ios/AFNetworking/AFHTTPSessionManager.h"/>
<header-file src="src/ios/AFNetworking/AFNetworking.h"/>
<header-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.h"/>
<header-file src="src/ios/AFNetworking/AFSecurityPolicy.h"/>
<header-file src="src/ios/AFNetworking/AFURLRequestSerialization.h"/>
<header-file src="src/ios/AFNetworking/AFURLResponseSerialization.h"/>
<header-file src="src/ios/AFNetworking/AFURLSessionManager.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFHTTPSessionManager.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFNetworking.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFNetworkReachabilityManager.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFSecurityPolicy.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFURLRequestSerialization.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFURLResponseSerialization.h"/>
<header-file src="src/ios/SM_AFNetworking/SM_AFURLSessionManager.h"/>
<header-file src="src/ios/SDNetworkActivityIndicator/SDNetworkActivityIndicator.h"/>
<source-file src="src/ios/CordovaHttpPlugin.m"/>
<source-file src="src/ios/BinaryRequestSerializer.m"/>
<source-file src="src/ios/BinaryResponseSerializer.m"/>
<source-file src="src/ios/TextResponseSerializer.m"/>
<source-file src="src/ios/TextRequestSerializer.m"/>
<source-file src="src/ios/AFNetworking/AFHTTPSessionManager.m"/>
<source-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.m"/>
<source-file src="src/ios/AFNetworking/AFSecurityPolicy.m"/>
<source-file src="src/ios/AFNetworking/AFURLRequestSerialization.m"/>
<source-file src="src/ios/AFNetworking/AFURLResponseSerialization.m"/>
<source-file src="src/ios/AFNetworking/AFURLSessionManager.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFHTTPSessionManager.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFNetworkReachabilityManager.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFSecurityPolicy.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFURLRequestSerialization.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFURLResponseSerialization.m"/>
<source-file src="src/ios/SM_AFNetworking/SM_AFURLSessionManager.m"/>
<source-file src="src/ios/SDNetworkActivityIndicator/SDNetworkActivityIndicator.m"/>
<framework src="Security.framework"/>
<framework src="SystemConfiguration.framework"/>
Expand Down
2 changes: 1 addition & 1 deletion src/ios/BinaryRequestSerializer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>
#import "AFURLRequestSerialization.h"
#import "SM_AFURLRequestSerialization.h"

@interface BinaryRequestSerializer : AFHTTPRequestSerializer

Expand Down
2 changes: 1 addition & 1 deletion src/ios/BinaryRequestSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ + (instancetype)serializer
return serializer;
}

#pragma mark - AFURLRequestSerialization
#pragma mark - SM_AFURLRequestSerialization

- (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
withParameters:(id)parameters
Expand Down
2 changes: 1 addition & 1 deletion src/ios/BinaryResponseSerializer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>
#import "AFURLResponseSerialization.h"
#import "SM_AFURLResponseSerialization.h"

@interface BinaryResponseSerializer : AFHTTPResponseSerializer

Expand Down
14 changes: 7 additions & 7 deletions src/ios/BinaryResponseSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response
if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) {
if (self.acceptableStatusCodes && ![self.acceptableStatusCodes containsIndex:(NSUInteger)response.statusCode] && [response URL]) {
NSMutableDictionary *mutableUserInfo = [@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:NSLocalizedStringFromTable(@"Request failed: %@ (%ld)", @"AFNetworking", nil), [NSHTTPURLResponse localizedStringForStatusCode:response.statusCode], (long)response.statusCode],
NSLocalizedDescriptionKey: [NSString stringWithFormat:NSLocalizedStringFromTable(@"Request failed: %@ (%ld)", @"SM_AFNetworking", nil), [NSHTTPURLResponse localizedStringForStatusCode:response.statusCode], (long)response.statusCode],
NSURLErrorFailingURLErrorKey: [response URL],
AFNetworkingOperationFailingURLResponseErrorKey: response,
SM_AFNetworkingOperationFailingURLResponseErrorKey: response,
} mutableCopy];

if (data) {
mutableUserInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] = data;
mutableUserInfo[SM_AFNetworkingOperationFailingURLResponseDataErrorKey] = data;

// trying to decode error message in body
mutableUserInfo[AFNetworkingOperationFailingURLResponseBodyErrorKey] = [self decodeResponseData:data withEncoding:[self getEncoding:response]];
mutableUserInfo[SM_AFNetworkingOperationFailingURLResponseBodyErrorKey] = [self decodeResponseData:data withEncoding:[self getEncoding:response]];
}

if (error) {
*error = [NSError errorWithDomain:AFURLResponseSerializationErrorDomain code:NSURLErrorBadServerResponse userInfo:mutableUserInfo];
*error = [NSError errorWithDomain:SM_AFURLResponseSerializationErrorDomain code:NSURLErrorBadServerResponse userInfo:mutableUserInfo];
}

return NO;
Expand All @@ -108,14 +108,14 @@ - (BOOL)validateResponse:(NSHTTPURLResponse *)response
return YES;
}

#pragma mark - AFURLResponseSerialization
#pragma mark - SM_AFURLResponseSerialization

- (id)responseObjectForResponse:(NSURLResponse *)response
data:(NSData *)data
error:(NSError *__autoreleasing *)error
{
if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) {
if (!error || AFErrorOrUnderlyingErrorHasCodeInDomain(*error, NSURLErrorCannotDecodeContentData, AFURLResponseSerializationErrorDomain)) {
if (!error || AFErrorOrUnderlyingErrorHasCodeInDomain(*error, NSURLErrorCannotDecodeContentData, SM_AFURLResponseSerializationErrorDomain)) {
return nil;
}
}
Expand Down
42 changes: 21 additions & 21 deletions src/ios/CordovaHttpPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#import "BinaryResponseSerializer.h"
#import "TextResponseSerializer.h"
#import "TextRequestSerializer.h"
#import "AFHTTPSessionManager.h"
#import "SM_AFHTTPSessionManager.h"
#import "SDNetworkActivityIndicator.h"

@interface CordovaHttpPlugin()

- (void)addRequest:(NSNumber*)reqId forTask:(NSURLSessionDataTask*)task;
- (void)removeRequest:(NSNumber*)reqId;
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager;
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(SM_AFHTTPSessionManager*)manager;
- (void)handleSuccess:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response andData:(id)data;
- (void)handleError:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response error:(NSError*)error;
- (NSNumber*)getStatusCode:(NSError*) error;
- (NSMutableDictionary*)copyHeaderFields:(NSDictionary*)headerFields;
- (void)setTimeout:(NSTimeInterval)timeout forManager:(AFHTTPSessionManager*)manager;
- (void)setRedirect:(bool)redirect forManager:(AFHTTPSessionManager*)manager;
- (void)setTimeout:(NSTimeInterval)timeout forManager:(SM_AFHTTPSessionManager*)manager;
- (void)setRedirect:(bool)redirect forManager:(SM_AFHTTPSessionManager*)manager;

@end

@implementation CordovaHttpPlugin {
AFSecurityPolicy *securityPolicy;
SM_AFSecurityPolicy *securityPolicy;
NSURLCredential *x509Credential;
NSMutableDictionary *reqDict;
}

- (void)pluginInitialize {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy = [SM_AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
reqDict = [NSMutableDictionary dictionary];
}

Expand All @@ -40,7 +40,7 @@ - (void)removeRequest:(NSNumber*)reqId {
[reqDict removeObjectForKey:reqId];
}

- (void)setRequestSerializer:(NSString*)serializerName forManager:(AFHTTPSessionManager*)manager {
- (void)setRequestSerializer:(NSString*)serializerName forManager:(SM_AFHTTPSessionManager*)manager {
if ([serializerName isEqualToString:@"json"]) {
manager.requestSerializer = [AFJSONRequestSerializer serializer];
} else if ([serializerName isEqualToString:@"utf8"]) {
Expand All @@ -52,7 +52,7 @@ - (void)setRequestSerializer:(NSString*)serializerName forManager:(AFHTTPSession
}
}

- (void)setupAuthChallengeBlock:(AFHTTPSessionManager*)manager {
- (void)setupAuthChallengeBlock:(SM_AFHTTPSessionManager*)manager {
[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition(
NSURLSession * _Nonnull session,
NSURLAuthenticationChallenge * _Nonnull challenge,
Expand All @@ -79,13 +79,13 @@ - (void)setupAuthChallengeBlock:(AFHTTPSessionManager*)manager {
}];
}

- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager {
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(SM_AFHTTPSessionManager*)manager {
[headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[manager.requestSerializer setValue:obj forHTTPHeaderField:key];
}];
}

- (void)setRedirect:(bool)followRedirect forManager:(AFHTTPSessionManager*)manager {
- (void)setRedirect:(bool)followRedirect forManager:(SM_AFHTTPSessionManager*)manager {
[manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest * _Nonnull(NSURLSession * _Nonnull session,
NSURLSessionTask * _Nonnull task, NSURLResponse * _Nonnull response, NSURLRequest * _Nonnull request) {

Expand All @@ -97,11 +97,11 @@ - (void)setRedirect:(bool)followRedirect forManager:(AFHTTPSessionManager*)manag
}];
}

- (void)setTimeout:(NSTimeInterval)timeout forManager:(AFHTTPSessionManager*)manager {
- (void)setTimeout:(NSTimeInterval)timeout forManager:(SM_AFHTTPSessionManager*)manager {
[manager.requestSerializer setTimeoutInterval:timeout];
}

- (void)setResponseSerializer:(NSString*)responseType forManager:(AFHTTPSessionManager*)manager {
- (void)setResponseSerializer:(NSString*)responseType forManager:(SM_AFHTTPSessionManager*)manager {
if ([responseType isEqualToString: @"text"] || [responseType isEqualToString: @"json"]) {
manager.responseSerializer = [TextResponseSerializer serializer];
} else {
Expand Down Expand Up @@ -133,8 +133,8 @@ - (void)handleError:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResp
[dictionary setObject:[self copyHeaderFields:response.allHeaderFields] forKey:@"headers"];
if(!aborted){
[dictionary setObject:[NSNumber numberWithInt:(int)response.statusCode] forKey:@"status"];
if (error.userInfo[AFNetworkingOperationFailingURLResponseBodyErrorKey]) {
[dictionary setObject:error.userInfo[AFNetworkingOperationFailingURLResponseBodyErrorKey] forKey:@"error"];
if (error.userInfo[SM_AFNetworkingOperationFailingURLResponseBodyErrorKey]) {
[dictionary setObject:error.userInfo[SM_AFNetworkingOperationFailingURLResponseBodyErrorKey] forKey:@"error"];
}
}
} else if(!aborted) {
Expand Down Expand Up @@ -193,7 +193,7 @@ - (NSMutableDictionary*)copyHeaderFields:(NSDictionary *)headerFields {
}

- (void)executeRequestWithoutData:(CDVInvokedUrlCommand*)command withMethod:(NSString*) method {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
SM_AFHTTPSessionManager *manager = [SM_AFHTTPSessionManager manager];

NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *headers = [command.arguments objectAtIndex:1];
Expand Down Expand Up @@ -253,7 +253,7 @@ - (void)executeRequestWithoutData:(CDVInvokedUrlCommand*)command withMethod:(NSS
}

- (void)executeRequestWithData:(CDVInvokedUrlCommand*)command withMethod:(NSString*)method {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
SM_AFHTTPSessionManager *manager = [SM_AFHTTPSessionManager manager];

NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *data = [command.arguments objectAtIndex:1];
Expand Down Expand Up @@ -351,15 +351,15 @@ - (void)setServerTrustMode:(CDVInvokedUrlCommand*)command {
NSString *certMode = [command.arguments objectAtIndex:0];

if ([certMode isEqualToString: @"default"] || [certMode isEqualToString: @"legacy"]) {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy = [SM_AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = NO;
securityPolicy.validatesDomainName = YES;
} else if ([certMode isEqualToString: @"nocheck"]) {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy = [SM_AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;
securityPolicy.validatesDomainName = NO;
} else if ([certMode isEqualToString: @"pinned"]) {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
securityPolicy = [SM_AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
securityPolicy.allowInvalidCertificates = NO;
securityPolicy.validatesDomainName = YES;
}
Expand Down Expand Up @@ -442,7 +442,7 @@ - (void)options:(CDVInvokedUrlCommand*)command {
}

- (void)uploadFiles:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
SM_AFHTTPSessionManager *manager = [SM_AFHTTPSessionManager manager];

NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *headers = [command.arguments objectAtIndex:1];
Expand Down Expand Up @@ -510,7 +510,7 @@ - (void)uploadFiles:(CDVInvokedUrlCommand*)command {
}

- (void)downloadFile:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
SM_AFHTTPSessionManager *manager = [SM_AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

NSString *url = [command.arguments objectAtIndex:0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AFHTTPSessionManager.h
// SM_AFHTTPSessionManager.h
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -31,14 +31,14 @@
#import <CoreServices/CoreServices.h>
#endif

#import "AFURLSessionManager.h"
#import "SM_AFURLSessionManager.h"

/**
`AFHTTPSessionManager` is a subclass of `AFURLSessionManager` with convenience methods for making HTTP requests. When a `baseURL` is provided, requests made with the `GET` / `POST` / et al. convenience methods can be made with relative paths.
`SM_AFHTTPSessionManager` is a subclass of `SM_AFURLSessionManager` with convenience methods for making HTTP requests. When a `baseURL` is provided, requests made with the `GET` / `POST` / et al. convenience methods can be made with relative paths.
## Subclassing Notes
Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass `AFHTTPSessionManager`, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass `SM_AFHTTPSessionManager`, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
For developers targeting iOS 6 or Mac OS X 10.8 or earlier, `AFHTTPRequestOperationManager` may be used to similar effect.
Expand All @@ -48,9 +48,9 @@
## Serialization
Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to `<AFURLRequestSerialization>`.
Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to `<SM_AFURLRequestSerialization>`.
Responses received from the server are automatically validated and serialized by the `responseSerializers` property, which is an object conforming to `<AFURLResponseSerialization>`
Responses received from the server are automatically validated and serialized by the `responseSerializers` property, which is an object conforming to `<SM_AFURLResponseSerialization>`
## URL Construction Using Relative Paths
Expand All @@ -73,7 +73,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface AFHTTPSessionManager : AFURLSessionManager <NSSecureCoding, NSCopying>
@interface SM_AFHTTPSessionManager : SM_AFURLSessionManager <NSSecureCoding, NSCopying>

/**
The URL used to construct requests from relative paths in methods like `requestWithMethod:URLString:parameters:`, and the `GET` / `POST` / et al. convenience methods.
Expand All @@ -85,26 +85,26 @@ NS_ASSUME_NONNULL_BEGIN
@warning `requestSerializer` must not be `nil`.
*/
@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
@property (nonatomic, strong) AFHTTPRequestSerializer <SM_AFURLRequestSerialization> * requestSerializer;

/**
Responses sent from the server in data tasks created with `dataTaskWithRequest:success:failure:` and run using the `GET` / `POST` / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance of `AFJSONResponseSerializer`.
@warning `responseSerializer` must not be `nil`.
*/
@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
@property (nonatomic, strong) AFHTTPResponseSerializer <SM_AFURLResponseSerialization> * responseSerializer;

///---------------------
/// @name Initialization
///---------------------

/**
Creates and returns an `AFHTTPSessionManager` object.
Creates and returns an `SM_AFHTTPSessionManager` object.
*/
+ (instancetype)manager;

/**
Initializes an `AFHTTPSessionManager` object with the specified base URL.
Initializes an `SM_AFHTTPSessionManager` object with the specified base URL.
@param url The base URL for the HTTP client.
Expand All @@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithBaseURL:(nullable NSURL *)url;

/**
Initializes an `AFHTTPSessionManager` object with the specified base URL.
Initializes an `SM_AFHTTPSessionManager` object with the specified base URL.
This is the designated initializer.
Expand Down
Loading

0 comments on commit c2a0317

Please sign in to comment.