Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving code from tkviewcontroller subclass to uiviewcontroller catego…

…ry, adding NSURLRequest property to tkhttprequest for post requests
  • Loading branch information...
commit bfbba0416f4561b0c798340d214e68b3d0bafeac 1 parent 422e064
@devinross authored
View
2  README.mdown
@@ -5,10 +5,10 @@ TapkuLibrary is an open source iOS framework built on Cocoa and UIKit intended f
### Classes
+* [TKHTTPRequest](https://github.com/devinross/tapkulibrary/blob/master/src/TapkuLibrary/TKHTTPRequest.h)
* [TKCoverflowView](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKCoverflowView.h)
* [TKCalendarMonthView](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKCalendarMonthView.h)
* [TKImageCenter](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKImageCenter.h)
-* [TKGraphView](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKGraphView.h)
* [TKAlertCenter](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKAlertCenter.h)
* [TKProgressAlertView](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKProgressAlertView.h)
* [TKLoadingView](https://github.com/devinross/tapkulibrary/tree/master/src/TapkuLibrary/TKLoadingView.h)
View
4 demo/Demo.xcodeproj/project.pbxproj
@@ -619,6 +619,10 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.2;
+ OTHER_LDFLAGS = (
+ "-all_load",
+ "-ObjC",
+ );
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
View
20 src/TapkuLibrary.xcodeproj/project.pbxproj
@@ -104,6 +104,8 @@
3BBF874C1296E976008AB2B1 /* TKTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BBF874A1296E976008AB2B1 /* TKTableViewController.m */; };
3BD32972125B753900BE5EAF /* TKAlertCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BD32970125B753900BE5EAF /* TKAlertCenter.h */; };
3BD32973125B753900BE5EAF /* TKAlertCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BD32971125B753900BE5EAF /* TKAlertCenter.m */; };
+ 3BE2036A149184CA003FFBEB /* UIViewController+TKCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BE20368149184CA003FFBEB /* UIViewController+TKCategory.h */; };
+ 3BE2036B149184CA003FFBEB /* UIViewController+TKCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BE20369149184CA003FFBEB /* UIViewController+TKCategory.m */; };
3BE54E61134548A100B59702 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BAC995910953DF400F235F1 /* MapKit.framework */; };
3BE54E7E134548CA00B59702 /* NSDictionary+TKCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BE54E7A134548CA00B59702 /* NSDictionary+TKCategory.h */; };
3BE54E7F134548CA00B59702 /* NSDictionary+TKCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BE54E7B134548CA00B59702 /* NSDictionary+TKCategory.m */; };
@@ -208,6 +210,8 @@
3BBF874A1296E976008AB2B1 /* TKTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKTableViewController.m; sourceTree = "<group>"; };
3BD32970125B753900BE5EAF /* TKAlertCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKAlertCenter.h; sourceTree = "<group>"; };
3BD32971125B753900BE5EAF /* TKAlertCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKAlertCenter.m; sourceTree = "<group>"; };
+ 3BE20368149184CA003FFBEB /* UIViewController+TKCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+TKCategory.h"; sourceTree = "<group>"; };
+ 3BE20369149184CA003FFBEB /* UIViewController+TKCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+TKCategory.m"; sourceTree = "<group>"; };
3BE54E7A134548CA00B59702 /* NSDictionary+TKCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+TKCategory.h"; sourceTree = "<group>"; };
3BE54E7B134548CA00B59702 /* NSDictionary+TKCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+TKCategory.m"; sourceTree = "<group>"; };
3BE54E7C134548CA00B59702 /* NSMutableURLRequest+TKCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableURLRequest+TKCategory.h"; sourceTree = "<group>"; };
@@ -433,16 +437,22 @@
children = (
3BF000FC10957EE50062DA49 /* NSString+TKCategory.h */,
3BF000FD10957EE50062DA49 /* NSString+TKCategory.m */,
- 3BAC9A2310953E5200F235F1 /* NSDate+TKCategory.h */,
- 3BAC9A2410953E5200F235F1 /* NSDate+TKCategory.m */,
3B1DCEC81289B84400884CDF /* NSArray+TKCategory.h */,
3B1DCEC91289B84400884CDF /* NSArray+TKCategory.m */,
+ 3BAC9A2310953E5200F235F1 /* NSDate+TKCategory.h */,
+ 3BAC9A2410953E5200F235F1 /* NSDate+TKCategory.m */,
+ 3BE54E7A134548CA00B59702 /* NSDictionary+TKCategory.h */,
+ 3BE54E7B134548CA00B59702 /* NSDictionary+TKCategory.m */,
+ 3BE54E7C134548CA00B59702 /* NSMutableURLRequest+TKCategory.h */,
+ 3BE54E7D134548CA00B59702 /* NSMutableURLRequest+TKCategory.m */,
3BAC9A2110953E5200F235F1 /* UIView+TKCategory.h */,
3BAC9A2210953E5200F235F1 /* UIView+TKCategory.m */,
3BAC9A1F10953E5200F235F1 /* UIImage+TKCategory.h */,
3BAC9A2010953E5200F235F1 /* UIImage+TKCategory.m */,
3BB96F5612B55CD600C38F46 /* UIImageView+TKCategory.h */,
3BB96F5712B55CD600C38F46 /* UIImageView+TKCategory.m */,
+ 3BE20368149184CA003FFBEB /* UIViewController+TKCategory.h */,
+ 3BE20369149184CA003FFBEB /* UIViewController+TKCategory.m */,
3B4346E212DA6A240076579B /* UIButton+TKCategory.h */,
3B4346E312DA6A240076579B /* UIButton+TKCategory.m */,
3B166A6D137F38D7006298E6 /* UIColor+TKCategory.h */,
@@ -451,10 +461,6 @@
3BE8FF8412945C4400DBF3FC /* UIScrollview+TKCategory.m */,
3B07B7C8133ADAD8001B1C6F /* UIBarButtonItem+TKCategory.h */,
3B07B7C9133ADAD8001B1C6F /* UIBarButtonItem+TKCategory.m */,
- 3BE54E7A134548CA00B59702 /* NSDictionary+TKCategory.h */,
- 3BE54E7B134548CA00B59702 /* NSDictionary+TKCategory.m */,
- 3BE54E7C134548CA00B59702 /* NSMutableURLRequest+TKCategory.h */,
- 3BE54E7D134548CA00B59702 /* NSMutableURLRequest+TKCategory.m */,
);
name = Additions;
sourceTree = "<group>";
@@ -571,6 +577,7 @@
3B17D289142E3CD40090616F /* TKNetworkQueue.h in Headers */,
3B560B7214574E30005FBDBF /* TKImageCache.h in Headers */,
3B819B5414601DC500EC0097 /* TKViewController.h in Headers */,
+ 3BE2036A149184CA003FFBEB /* UIViewController+TKCategory.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -730,6 +737,7 @@
3B17D28A142E3CD40090616F /* TKNetworkQueue.m in Sources */,
3B560B7314574E30005FBDBF /* TKImageCache.m in Sources */,
3B819B5514601DC500EC0097 /* TKViewController.m in Sources */,
+ 3BE2036B149184CA003FFBEB /* UIViewController+TKCategory.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  ...uLibrary.xcodeproj/project.xcworkspace/xcuserdata/devinross14.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
10 src/TapkuLibrary/TKAppDelegate.m
@@ -38,9 +38,13 @@ @implementation TKAppDelegate
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- _window = [[TKWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- _window.backgroundColor = [UIColor blackColor];
- [_window makeKeyAndVisible];
+ if(self.window==nil){
+ self.window = [[TKWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
+ self.window.backgroundColor = [UIColor blackColor];
+ [self.window makeKeyAndVisible];
+ }
+
+
[self applicationDidStartup:application];
View
4 src/TapkuLibrary/TKHTTPRequest.h
@@ -80,7 +80,11 @@ typedef enum _TKNetworkErrorType {
+ (TKHTTPRequest*) requestWithURL:(NSURL*)URL;
- (id) initWithURL:(NSURL*)URL;
++ (TKHTTPRequest*) requestWithURLRequest:(NSURLRequest*)request;
+- (id) initWithURLRequest:(NSURLRequest*)request;
+
@property (strong,nonatomic) NSURL *URL;
+@property (strong,nonatomic) NSURLRequest *URLRequest;
@property (assign,nonatomic) NSUInteger tag;
@property (assign,nonatomic) BOOL showNetworkActivity; // for indiviual requests, default: TRUE
View
44 src/TapkuLibrary/TKHTTPRequest.m
@@ -69,19 +69,13 @@ + (BOOL) removeFileAtPath:(NSString *)path error:(NSError **)err;
- (void) _decreaseNetworkActivity;
- (void) _increaseNetworkActivity;
-
-
@property (assign, nonatomic) TKOperationState state;
@property (readwrite, nonatomic, assign, getter = isCancelled) BOOL cancelled;
-
-
@property (nonatomic,strong) NSURLConnection *connection;
@property (nonatomic,strong) NSMutableData *data;
@property (nonatomic,strong) NSFileHandle *fileHandler; // Used for writing data to a file when downloadDestinationPath is set
-
-
@end
@@ -93,10 +87,9 @@ @implementation TKHTTPRequest
@synthesize temporaryFileDownloadPath,downloadDestinationPath;
@synthesize didStartSelector,didFinishSelector,didFailSelector,delegate;
@synthesize progressDelegate;
-
@synthesize statusCode,responseHeaders,error;
@synthesize cancelled=_cancelled,state = _state;
-
+@synthesize URLRequest;
@synthesize connection,data,fileHandler;
@@ -137,6 +130,21 @@ - (id) initWithURL:(NSURL*)url{
return self;
}
+
++ (TKHTTPRequest*) requestWithURLRequest:(NSURLRequest*)request{
+ return [[self alloc] initWithURLRequest:request];
+}
+- (id) initWithURLRequest:(NSURLRequest*)request{
+ if(!(self=[super init])) return nil;
+
+ self.URLRequest = request;
+ self.showNetworkActivity = YES;
+ self.state = TKOperationStateInited;
+
+
+ return self;
+}
+
- (void) dealloc{
if(self.connection) [self.connection cancel];
}
@@ -165,7 +173,12 @@ - (void) _startOnNetworkThread{
_receivedDataBytes = 0;
_totalExpectedImageSize = 0;
- self.connection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:self.URL] delegate:self];
+ if(self.URLRequest)
+ self.connection = [[NSURLConnection alloc] initWithRequest:self.URLRequest delegate:self];
+ else
+ self.connection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:self.URL] delegate:self];
+
+
[self.connection start];
@@ -224,11 +237,14 @@ - (void) _completeRequest{
}
+ SEL mainThreadRoute;
+
if(self.error)
- [self performSelectorOnMainThread:@selector(_requestFailed) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ mainThreadRoute = @selector(_requestFailed);
else
- [self performSelectorOnMainThread:@selector(_requestFinished) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ mainThreadRoute = @selector(_requestFinished);
+ [self performSelectorOnMainThread:mainThreadRoute withObject:nil waitUntilDone:[NSThread isMainThread]];
}
@@ -353,8 +369,6 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection{
-
-
#pragma mark - Blocks
#if NS_BLOCKS_AVAILABLE
- (void) setStartedBlock:(TKBasicBlock)aStartedBlock{
@@ -459,7 +473,6 @@ - (void) _cancelOnRequestThread{
}
-
#pragma mark -
#pragma mark Network Activity
+ (BOOL) isNetworkInUse{
@@ -538,5 +551,4 @@ - (BOOL) removeDesitinationFile{
return (!err);
}
-
-@end
+@end
View
7 src/TapkuLibrary/TKNetworkQueue.m
@@ -39,6 +39,10 @@ + (TKNetworkQueue*) sharedNetworkQueue{
static TKNetworkQueue *sharedInstance = nil;
if (!sharedInstance) {
sharedInstance = [[TKNetworkQueue alloc] init];
+
+ [sharedInstance setMaxConcurrentOperationCount:4];
+
+
}
return sharedInstance;
}
@@ -47,6 +51,9 @@ + (TKNetworkQueue*) networkQueue{
}
- (id) init{
if(!(self=[super init])) return nil;
+
+
+
return self;
}
View
10 src/TapkuLibrary/TKViewController.h
@@ -41,16 +41,8 @@
- (void) addActiveRequest:(TKHTTPRequest*)request;
- (void) removeActiveRequest:(TKHTTPRequest*)request;
+- (void) cancelActiveRequests;
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback;
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback readingOptions:(NSJSONReadingOptions)options;
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor readingOptions:(NSJSONReadingOptions)options;
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector;
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector readingOptions:(NSJSONReadingOptions)options;
@end
View
102 src/TapkuLibrary/TKViewController.m
@@ -41,12 +41,7 @@ - (void) viewDidUnload{
[super viewDidUnload];
}
- (void) dealloc{
-
- if(_activeRequests){
- for(TKHTTPRequest *request in _activeRequests)
- [request cancel];
- }
-
+ [self cancelActiveRequests];
}
#pragma mark - EASILY MANAGE ACTIVE REQUESTS
@@ -63,97 +58,10 @@ - (void) removeActiveRequest:(TKHTTPRequest*)request{
if([_activeRequests containsObject:request])
[_activeRequests removeObject:request];
}
-
-
-#pragma mark - PROCESS JSON IN THE BACKGROUND
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback{
-
- [self processJSONDataInBackground:data
- withCallbackSelector:callback
- backgroundSelector:nil
- errorSelector:nil
- readingOptions:0];
-
-}
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback readingOptions:(NSJSONReadingOptions)options{
-
- [self processJSONDataInBackground:data
- withCallbackSelector:callback
- backgroundSelector:nil
- errorSelector:nil
- readingOptions:options];
-
-}
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor readingOptions:(NSJSONReadingOptions)options{
-
- [self processJSONDataInBackground:data
- withCallbackSelector:callback
- backgroundSelector:backgroundProcessor
- errorSelector:nil
- readingOptions:options];
-
-}
-
-- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector{
-
- [self processJSONDataInBackground:data
- withCallbackSelector:callback
- backgroundSelector:backgroundProcessor
- errorSelector:errroSelector
- readingOptions:0];
-
-}
-
-
-- (void) processJSONDataInBackground:(NSData *)data
- withCallbackSelector:(SEL)callback
- backgroundSelector:(SEL)backgroundProcessor
- errorSelector:(SEL)errroSelector
- readingOptions:(NSJSONReadingOptions)options{
-
-
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
-
- [dict setObject:data forKey:@"data"];
- [dict setObject:[NSNumber numberWithUnsignedInt:options] forKey:@"flags"];
-
- if(callback) [dict setObject:NSStringFromSelector(callback) forKey:@"callback"];
- if(backgroundProcessor) [dict setObject:NSStringFromSelector(backgroundProcessor) forKey:@"backgroundProcessor"];
- if(errroSelector) [dict setObject:NSStringFromSelector(errroSelector) forKey:@"errroSelector"];
-
-
- [self performSelectorInBackground:@selector(_processJSONData:) withObject:dict];
-
-
-}
-
-
-- (void) _processJSONData:(NSDictionary*)dict{
- @autoreleasepool {
- NSError *error = nil;
-
- NSData *data = [dict objectForKey:@"data"];
- NSUInteger options = [[dict objectForKey:@"flags"] unsignedIntValue];
-
- NSString *callback = [dict objectForKey:@"callback"];
- NSString *background = [dict objectForKey:@"backgroundProcessor"];
- NSString *eSelector = [dict objectForKey:@"errroSelector"];
-
- id object = [NSJSONSerialization JSONObjectWithData:data options:options error:&error];
-
-
-
- if(error){
- if(eSelector) [self performSelector:NSSelectorFromString(eSelector) withObject:error];
- }else{
- if(background) object = [self performSelector:NSSelectorFromString(background) withObject:object];
- [self performSelectorOnMainThread:NSSelectorFromString(callback) withObject:object waitUntilDone:NO];
- }
-
-
+- (void) cancelActiveRequests{
+ if(_activeRequests){
+ for(TKHTTPRequest *request in _activeRequests)
+ [request cancel];
}
}
View
1  src/TapkuLibrary/UIView+TKCategory.h
@@ -34,6 +34,7 @@
@interface UIView (TKCategory)
+- (void) addSubviewToBack:(UIView*)view;
- (void) roundOffFrame;
View
5 src/TapkuLibrary/UIView+TKCategory.m
@@ -34,6 +34,11 @@
@implementation UIView (TKCategory)
+- (void) addSubviewToBack:(UIView*)view{
+ [self addSubview:view];
+ [self sendSubviewToBack:view];
+}
+
- (void) roundOffFrame{
self.frame = CGRectMake((NSInteger)self.frame.origin.x, (NSInteger)self.frame.origin.y, (NSInteger)self.frame.size.width, (NSInteger)self.frame.size.height);
View
27 src/TapkuLibrary/UIViewController+TKCategory.h
@@ -0,0 +1,27 @@
+//
+// UIViewController+TKCategory.h
+// TapkuLibrary
+//
+// Created by Devin Ross on 12/8/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+@interface UIViewController (TKCategory)
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback;
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback readingOptions:(NSJSONReadingOptions)options;
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor readingOptions:(NSJSONReadingOptions)options;
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector;
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector readingOptions:(NSJSONReadingOptions)options;
+
+
+
+
+@end
View
108 src/TapkuLibrary/UIViewController+TKCategory.m
@@ -0,0 +1,108 @@
+//
+// UIViewController+TKCategory.m
+// TapkuLibrary
+//
+// Created by Devin Ross on 12/8/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "UIViewController+TKCategory.h"
+
+@implementation UIViewController (TKCategory)
+
+
+#pragma mark - PROCESS JSON IN THE BACKGROUND
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback{
+
+ [self processJSONDataInBackground:data
+ withCallbackSelector:callback
+ backgroundSelector:nil
+ errorSelector:nil
+ readingOptions:0];
+
+}
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback readingOptions:(NSJSONReadingOptions)options{
+
+ [self processJSONDataInBackground:data
+ withCallbackSelector:callback
+ backgroundSelector:nil
+ errorSelector:nil
+ readingOptions:options];
+
+}
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor readingOptions:(NSJSONReadingOptions)options{
+
+ [self processJSONDataInBackground:data
+ withCallbackSelector:callback
+ backgroundSelector:backgroundProcessor
+ errorSelector:nil
+ readingOptions:options];
+
+}
+
+- (void) processJSONDataInBackground:(NSData *)data withCallbackSelector:(SEL)callback backgroundSelector:(SEL)backgroundProcessor errorSelector:(SEL)errroSelector{
+
+ [self processJSONDataInBackground:data
+ withCallbackSelector:callback
+ backgroundSelector:backgroundProcessor
+ errorSelector:errroSelector
+ readingOptions:0];
+
+}
+
+
+- (void) processJSONDataInBackground:(NSData *)data
+ withCallbackSelector:(SEL)callback
+ backgroundSelector:(SEL)backgroundProcessor
+ errorSelector:(SEL)errroSelector
+ readingOptions:(NSJSONReadingOptions)options{
+
+
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+
+ [dict setObject:data forKey:@"data"];
+ [dict setObject:[NSNumber numberWithUnsignedInt:options] forKey:@"flags"];
+
+ if(callback) [dict setObject:NSStringFromSelector(callback) forKey:@"callback"];
+ if(backgroundProcessor) [dict setObject:NSStringFromSelector(backgroundProcessor) forKey:@"backgroundProcessor"];
+ if(errroSelector) [dict setObject:NSStringFromSelector(errroSelector) forKey:@"errroSelector"];
+
+
+ [self performSelectorInBackground:@selector(_processJSONData:) withObject:dict];
+
+
+}
+
+
+- (void) _processJSONData:(NSDictionary*)dict{
+ @autoreleasepool {
+ NSError *error = nil;
+
+ NSData *data = [dict objectForKey:@"data"];
+ NSUInteger options = [[dict objectForKey:@"flags"] unsignedIntValue];
+
+ NSString *callback = [dict objectForKey:@"callback"];
+ NSString *background = [dict objectForKey:@"backgroundProcessor"];
+ NSString *eSelector = [dict objectForKey:@"errroSelector"];
+
+ id object = [NSJSONSerialization JSONObjectWithData:data options:options error:&error];
+
+
+
+ if(error){
+ if(eSelector) [self performSelector:NSSelectorFromString(eSelector) withObject:error];
+ }else{
+ if(background) object = [self performSelector:NSSelectorFromString(background) withObject:object];
+ [self performSelectorOnMainThread:NSSelectorFromString(callback) withObject:object waitUntilDone:NO];
+ }
+
+
+ }
+}
+
+
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.