Restore iOS 4.0 compatibility.

Signed-off-by: Zachary Waldowski <zwaldowski@gmail.com>
This commit is contained in:
Zachary Waldowski 2012-04-28 17:57:41 -04:00
parent 904d6ba50d
commit 25620fe839
5 changed files with 18 additions and 12 deletions

View file

@ -54,9 +54,9 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) {
return [NSSet setWithSet:mutableContentTypes]; return [NSSet setWithSet:mutableContentTypes];
} }
static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, void *block) { static void AFSwizzleClassMethodWithImplementation(Class klass, SEL selector, IMP implementation) {
Method originalMethod = class_getClassMethod(klass, selector); Method originalMethod = class_getClassMethod(klass, selector);
IMP implementation = imp_implementationWithBlock(block); if (method_getImplementation(originalMethod) != implementation)
class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
} }
@ -261,6 +261,10 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) {
#pragma mark - AFHTTPRequestOperation #pragma mark - AFHTTPRequestOperation
static id AFStaticClassValueImplementation(id self, SEL _cmd) {
return objc_getAssociatedObject([self class], _cmd);
}
+ (NSIndexSet *)acceptableStatusCodes { + (NSIndexSet *)acceptableStatusCodes {
return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
} }
@ -268,9 +272,9 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) {
+ (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes {
NSMutableIndexSet *mutableStatusCodes = [[[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]] autorelease]; NSMutableIndexSet *mutableStatusCodes = [[[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]] autorelease];
[mutableStatusCodes addIndexes:statusCodes]; [mutableStatusCodes addIndexes:statusCodes];
AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(id _self) { SEL selector = @selector(acceptableStatusCodes);
return mutableStatusCodes; AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation);
}); objc_setAssociatedObject([self class], selector, mutableStatusCodes, OBJC_ASSOCIATION_COPY_NONATOMIC);
} }
+ (NSSet *)acceptableContentTypes { + (NSSet *)acceptableContentTypes {
@ -280,9 +284,9 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) {
+ (void)addAcceptableContentTypes:(NSSet *)contentTypes { + (void)addAcceptableContentTypes:(NSSet *)contentTypes {
NSMutableSet *mutableContentTypes = [[[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES] autorelease]; NSMutableSet *mutableContentTypes = [[[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES] autorelease];
[mutableContentTypes unionSet:contentTypes]; [mutableContentTypes unionSet:contentTypes];
AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(id _self) { SEL selector = @selector(acceptableContentTypes);
return mutableContentTypes; AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation);
}); objc_setAssociatedObject([self class], selector, mutableContentTypes, OBJC_ASSOCIATION_COPY_NONATOMIC);
} }
+ (BOOL)canProcessRequest:(NSURLRequest *)request { + (BOOL)canProcessRequest:(NSURLRequest *)request {

View file

@ -1,7 +1,5 @@
= 1.0RC1 / 2012-04-25 = 1.0RC1 / 2012-04-25
* Note: 1.0RC1 Deprecates iOS < 4.3 compatibility because of the addition of `AFHTTPRequestOperation +addAcceptableStatusCodes / +addAcceptableContentTypes`
* Add `AFHTTPRequestOperation +addAcceptableStatusCodes / * Add `AFHTTPRequestOperation +addAcceptableStatusCodes /
+addAcceptableContentTypes` to dynamically add acceptable status codes and +addAcceptableContentTypes` to dynamically add acceptable status codes and
content types on the class level (Mattt Thompson) content types on the class level (Mattt Thompson)

View file

@ -381,6 +381,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch; GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = Info.plist; INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app; WRAPPER_EXTENSION = app;
}; };
@ -392,6 +393,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch; GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = Info.plist; INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app; WRAPPER_EXTENSION = app;
}; };

View file

@ -143,7 +143,7 @@ operation.outputStream = [NSOutputStream outputStreamToMemory];
## Requirements ## Requirements
AFNetworking requires either [iOS 4.3](http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html%23//apple_ref/doc/uid/TP40009559-SW1) and above, or [Mac OS 10.6](http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html#//apple_ref/doc/uid/TP40008898-SW7) and above. AFNetworking requires either [iOS 4.0](http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html) and above, or [Mac OS 10.6](http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html#//apple_ref/doc/uid/TP40008898-SW7) and above.
AFNetworking uses [`NSJSONSerialization`](http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) if it is available. If your app targets a platform where this class is not available you can include one of the following JSON libraries to your project for AFNetworking to automatically detect and use. AFNetworking uses [`NSJSONSerialization`](http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) if it is available. If your app targets a platform where this class is not available you can include one of the following JSON libraries to your project for AFNetworking to automatically detect and use.

View file

@ -392,6 +392,7 @@
GCC_WARN_SIGN_COMPARE = YES; GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNUSED_PARAMETER = NO; GCC_WARN_UNUSED_PARAMETER = NO;
INFOPLIST_FILE = Info.plist; INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app; WRAPPER_EXTENSION = app;
}; };
@ -410,6 +411,7 @@
GCC_WARN_SIGN_COMPARE = YES; GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNUSED_PARAMETER = NO; GCC_WARN_UNUSED_PARAMETER = NO;
INFOPLIST_FILE = Info.plist; INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
WRAPPER_EXTENSION = app; WRAPPER_EXTENSION = app;