Skip to content

Commit

Permalink
Restore iOS 4.0 compatibility.
Browse files Browse the repository at this point in the history
Signed-off-by: Zachary Waldowski <[email protected]>
  • Loading branch information
zwaldowski committed Apr 28, 2012
1 parent 904d6ba commit 25620fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
22 changes: 13 additions & 9 deletions AFNetworking/AFHTTPRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
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);
IMP implementation = imp_implementationWithBlock(block);
class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
if (method_getImplementation(originalMethod) != implementation)
class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
}

static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
Expand Down Expand Up @@ -261,16 +261,20 @@ - (void)setResponseFilePath:(NSString *)responseFilePath {

#pragma mark - AFHTTPRequestOperation

static id AFStaticClassValueImplementation(id self, SEL _cmd) {
return objc_getAssociatedObject([self class], _cmd);
}

+ (NSIndexSet *)acceptableStatusCodes {
return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
}

+ (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes {
NSMutableIndexSet *mutableStatusCodes = [[[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]] autorelease];
[mutableStatusCodes addIndexes:statusCodes];
AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(id _self) {
return mutableStatusCodes;
});
SEL selector = @selector(acceptableStatusCodes);
AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation);
objc_setAssociatedObject([self class], selector, mutableStatusCodes, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

+ (NSSet *)acceptableContentTypes {
Expand All @@ -280,9 +284,9 @@ + (NSSet *)acceptableContentTypes {
+ (void)addAcceptableContentTypes:(NSSet *)contentTypes {
NSMutableSet *mutableContentTypes = [[[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES] autorelease];
[mutableContentTypes unionSet:contentTypes];
AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(id _self) {
return mutableContentTypes;
});
SEL selector = @selector(acceptableContentTypes);
AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation);
objc_setAssociatedObject([self class], selector, mutableContentTypes, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

+ (BOOL)canProcessRequest:(NSURLRequest *)request {
Expand Down
2 changes: 0 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
= 1.0RC1 / 2012-04-25

* Note: 1.0RC1 Deprecates iOS < 4.3 compatibility because of the addition of `AFHTTPRequestOperation +addAcceptableStatusCodes / +addAcceptableContentTypes`

* Add `AFHTTPRequestOperation +addAcceptableStatusCodes /
+addAcceptableContentTypes` to dynamically add acceptable status codes and
content types on the class level (Mattt Thompson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -392,6 +393,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ operation.outputStream = [NSOutputStream outputStreamToMemory];

## 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNUSED_PARAMETER = NO;
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -410,6 +411,7 @@
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNUSED_PARAMETER = NO;
INFOPLIST_FILE = Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
VALIDATE_PRODUCT = YES;
WRAPPER_EXTENSION = app;
Expand Down

0 comments on commit 25620fe

Please sign in to comment.