Last active
August 29, 2015 13:57
-
-
Save nenadvulic/9600443 to your computer and use it in GitHub Desktop.
Fake network data using with OHHTTPStubs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyViewController.h" | |
#import <OHHTTPStubs/OHHTTPStubs.h> | |
@interface FLUSubscribeViewController(){ | |
id<OHHTTPStubsDescriptor> _stub; | |
} | |
@end | |
@implementation FLUSubscribeViewController | |
-(void)stubWithFile:(NSString*)filename{ | |
_stub = [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { | |
//you can do the job only for particular route for exemple /new/user | |
return YES; | |
} withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { | |
//here you can handle with status code and headers | |
return [OHHTTPStubsResponse responseWithFileAtPath:OHPathForFileInBundle(filename, nil) | |
statusCode:200 headers:@{@"Content-Type":@"text/json"}]; | |
}]; | |
} | |
- (void) viewDidAppear:(BOOL)animated{ | |
[super viewDidAppear:animated]; | |
[self stubWithFile:@"my_response_json.json"]; | |
} | |
- (void) viewDidDisappear:(BOOL)animated{ | |
[super viewDidDisappear:animated]; | |
if ( _stub ){ | |
[OHHTTPStubs removeStub:_stub]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment