Created
March 17, 2012 16:27
-
-
Save jefflinwood/2061788 to your computer and use it in GitHub Desktop.
Drupal iOS SDK with blocks instead of delegates - example DIOSView class, with implementation in DrupalMapApp
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
// | |
// DIOSView.h | |
// DrupalMapApp | |
// | |
// Created by Jeffrey Linwood on 3/17/12. | |
// Copyright (c) 2012 Jeff Linwood. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "AFHTTPRequestOperation.h" | |
@interface DIOSView : NSObject | |
/** | |
Returns the contents of the specified Drupal view. Implementation takes two blocks, one for success, and one for failure. Either parameter may be nil. | |
@param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request. | |
@param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occured during the request. | |
*/ | |
- (void)getView:(NSString *)viewName success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success | |
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure; | |
@end |
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
// | |
// DIOSView.m | |
// DrupalMapApp | |
// | |
// Created by Jeffrey Linwood on 3/17/12. | |
// Copyright (c) 2012 Jeff Linwood. All rights reserved. | |
// | |
#import "DIOSView.h" | |
#import "DIOSSession.h" | |
@implementation DIOSView | |
/** | |
Returns the contents of the specified Drupal view. Implementation takes two blocks, one for success, and one for failure. Either parameter may be nil. | |
@param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request. | |
@param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occured during the request. | |
*/ | |
- (void)getView:(NSString *)viewName success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success | |
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure { | |
[[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseView, viewName] parameters:nil success:success failure:failure]; | |
} | |
@end |
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
- (void)viewDidAppear:(BOOL)animated{ | |
if ([[[AppData sharedInstance] businesses] count] != 0) { | |
//we've already loaded data once for this app, so just display it on the map | |
[self loadMapData]; | |
} else { | |
[SVProgressHUD showWithStatus:@"Retrieving Data"]; | |
DIOSView *diosView = [[DIOSView alloc] init]; | |
[diosView getView:@"businesses.json" success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
//store results from the view into the application wide data | |
[[AppData sharedInstance] storeResults:responseObject]; | |
[self loadMapData]; | |
[SVProgressHUD dismissWithSuccess:@"Downloaded"]; | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
[SVProgressHUD dismissWithError:@"Unable to download data" afterDelay:5]; | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment