如何爲iOS < 5實施-[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
5?iOS4的實現 - [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]?
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
#import <objc/runtime.h>
#import "NSURLConnection+iOS4.h"
// Dynamically add -[NSURLConnection sendAsynchronousRequest:queue:completionHandler:].
void *sendAsynchronousRequest4(id self, SEL _cmd, NSURLRequest *request, NSOperationQueue *queue, void (^handler)(NSURLResponse*, NSData*, NSError*));
void *sendAsynchronousRequest4(id self, SEL _cmd, NSURLRequest *request, NSOperationQueue *queue, void (^handler)(NSURLResponse*, NSData*, NSError*)) {
// How should we implement this?
}
@implementation NSURLConnection (SendAsync)
+ (void)load {
SEL sendAsyncSelector = @selector(sendAsynchronousRequest:queue:completionHandler:);
if (![NSURLConnection instancesRespondToSelector:]) {
class_addMethod([self class], sendAsyncSelector, (IMP)sendAsynchronousRequest4, "[email protected]:@@@");
}
}
@end
#endif
RestKit不支持
KDaker
2013-01-23 01:01:46