mirror of
https://github.com/gimenete/iOS-boilerplate.git
synced 2026-01-10 23:18:07 -05:00
Merge pull request #17 from mattt/master
Remove Image Manager and BaseViewController; Add Twitter Search Client
This commit is contained in:
@@ -45,8 +45,6 @@
|
||||
09885EC11418F2E600CCE17A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 09885EBF1418F2E600CCE17A /* InfoPlist.strings */; };
|
||||
09885EC31418F2E600CCE17A /* IOSBoilerplateTests.h in Resources */ = {isa = PBXBuildFile; fileRef = 09885EC21418F2E600CCE17A /* IOSBoilerplateTests.h */; };
|
||||
09885EC51418F2E600CCE17A /* IOSBoilerplateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885EC41418F2E600CCE17A /* IOSBoilerplateTests.m */; };
|
||||
09885EF91418F4AB00CCE17A /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885EF81418F4AB00CCE17A /* BaseViewController.m */; };
|
||||
09885F381418F73A00CCE17A /* ImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885F371418F73A00CCE17A /* ImageManager.m */; };
|
||||
09885F3C1418FC6F00CCE17A /* HTTPHUDExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 09885F3A1418FC6E00CCE17A /* HTTPHUDExample.m */; };
|
||||
09885F3D1418FC6F00CCE17A /* HTTPHUDExample.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09885F3B1418FC6E00CCE17A /* HTTPHUDExample.xib */; };
|
||||
09885F421418FFE000CCE17A /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 09885F3F1418FFE000CCE17A /* SVProgressHUD.bundle */; };
|
||||
@@ -84,6 +82,7 @@
|
||||
D8EA24CF145BA4AC00EB08B3 /* right@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D8EA24CB145BA4AC00EB08B3 /* right@2x.png */; };
|
||||
D8EA24D3145BA4BC00EB08B3 /* BrowserSampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D8EA24D1145BA4BC00EB08B3 /* BrowserSampleViewController.m */; };
|
||||
D8EA24D4145BA4BC00EB08B3 /* BrowserSampleViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8EA24D2145BA4BC00EB08B3 /* BrowserSampleViewController.xib */; };
|
||||
F87266BC145EF4E200B775D3 /* TwitterSearchClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -160,10 +159,6 @@
|
||||
09885EEC1418F3F900CCE17A /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
|
||||
09885EEE1418F40200CCE17A /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
||||
09885EF11418F44200CCE17A /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
|
||||
09885EF71418F4AB00CCE17A /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = "<group>"; };
|
||||
09885EF81418F4AB00CCE17A /* BaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseViewController.m; sourceTree = "<group>"; };
|
||||
09885F361418F73A00CCE17A /* ImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageManager.h; sourceTree = "<group>"; };
|
||||
09885F371418F73A00CCE17A /* ImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageManager.m; sourceTree = "<group>"; };
|
||||
09885F391418FC6E00CCE17A /* HTTPHUDExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPHUDExample.h; sourceTree = "<group>"; };
|
||||
09885F3A1418FC6E00CCE17A /* HTTPHUDExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPHUDExample.m; sourceTree = "<group>"; };
|
||||
09885F3B1418FC6E00CCE17A /* HTTPHUDExample.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HTTPHUDExample.xib; sourceTree = "<group>"; };
|
||||
@@ -218,6 +213,8 @@
|
||||
D8EA24D0145BA4BC00EB08B3 /* BrowserSampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BrowserSampleViewController.h; sourceTree = "<group>"; };
|
||||
D8EA24D1145BA4BC00EB08B3 /* BrowserSampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BrowserSampleViewController.m; sourceTree = "<group>"; };
|
||||
D8EA24D2145BA4BC00EB08B3 /* BrowserSampleViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BrowserSampleViewController.xib; sourceTree = "<group>"; };
|
||||
F87266BA145EF4E200B775D3 /* TwitterSearchClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwitterSearchClient.h; sourceTree = "<group>"; };
|
||||
F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TwitterSearchClient.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -418,10 +415,6 @@
|
||||
09885EF61418F48F00CCE17A /* Helpers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
09885EF71418F4AB00CCE17A /* BaseViewController.h */,
|
||||
09885EF81418F4AB00CCE17A /* BaseViewController.m */,
|
||||
09885F361418F73A00CCE17A /* ImageManager.h */,
|
||||
09885F371418F73A00CCE17A /* ImageManager.m */,
|
||||
09885F46141901E700CCE17A /* DictionaryHelper.h */,
|
||||
09885F47141901E700CCE17A /* DictionaryHelper.m */,
|
||||
09885F5714190D7900CCE17A /* FastCell.h */,
|
||||
@@ -432,6 +425,8 @@
|
||||
09270763141E4EC900E778AE /* DataHelper.m */,
|
||||
09E442CE141F97AE00AD2DAE /* ListViewController.h */,
|
||||
09E442CF141F97AE00AD2DAE /* ListViewController.m */,
|
||||
F87266BA145EF4E200B775D3 /* TwitterSearchClient.h */,
|
||||
F87266BB145EF4E200B775D3 /* TwitterSearchClient.m */,
|
||||
);
|
||||
name = Helpers;
|
||||
sourceTree = "<group>";
|
||||
@@ -634,8 +629,6 @@
|
||||
09885EA11418F2E600CCE17A /* main.m in Sources */,
|
||||
09885EA51418F2E600CCE17A /* IOSBoilerplateAppDelegate.m in Sources */,
|
||||
09885EAB1418F2E600CCE17A /* RootViewController.m in Sources */,
|
||||
09885EF91418F4AB00CCE17A /* BaseViewController.m in Sources */,
|
||||
09885F381418F73A00CCE17A /* ImageManager.m in Sources */,
|
||||
09885F3C1418FC6F00CCE17A /* HTTPHUDExample.m in Sources */,
|
||||
09885F431418FFE000CCE17A /* SVProgressHUD.m in Sources */,
|
||||
09885F48141901E700CCE17A /* DictionaryHelper.m in Sources */,
|
||||
@@ -669,6 +662,7 @@
|
||||
D8EA24C4145BA49100EB08B3 /* BrowserViewController.m in Sources */,
|
||||
D8EA24C6145BA49100EB08B3 /* MyApplication.m in Sources */,
|
||||
D8EA24D3145BA4BC00EB08B3 /* BrowserSampleViewController.m in Sources */,
|
||||
F87266BC145EF4E200B775D3 /* TwitterSearchClient.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
//
|
||||
|
||||
#import "AsyncCell.h"
|
||||
#import "ImageManager.h"
|
||||
#import "DictionaryHelper.h"
|
||||
|
||||
#import "UIImageView+AFNetworking.h"
|
||||
|
||||
@implementation AsyncCell
|
||||
|
||||
@synthesize info;
|
||||
@@ -84,20 +85,21 @@ static UIFont* bold14 = nil;
|
||||
[[UIColor grayColor] set];
|
||||
[text drawInRect:CGRectMake(63.0, 25.0, widthr, 20.0) withFont:system14 lineBreakMode:UILineBreakModeTailTruncation];
|
||||
|
||||
if (image) {
|
||||
if (self.image) {
|
||||
CGRect r = CGRectMake(5.0, 5.0, 48.0, 48.0);
|
||||
[image drawInRect:r];
|
||||
[self.image drawInRect:r];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) updateCellInfo:(NSDictionary*)_info {
|
||||
self.info = _info;
|
||||
NSString* url = [info stringForKey:@"profile_image_url"];
|
||||
if (url) {
|
||||
[ImageManager loadImage:url success:^(UIImage* img) {
|
||||
self.image = img;
|
||||
NSString *urlString = [info stringForKey:@"profile_image_url"];
|
||||
if (urlString) {
|
||||
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] success:^(UIImage *requestedImage) {
|
||||
self.image = requestedImage;
|
||||
[self setNeedsDisplay];
|
||||
}];
|
||||
[operation start];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AsyncCellImagesExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
@interface AsyncCellImagesExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UITableView* table;
|
||||
@property (nonatomic, retain) NSArray* results;
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
|
||||
#import "AsyncCellImagesExample.h"
|
||||
#import "SVProgressHUD.h"
|
||||
#import "JSONKit.h"
|
||||
#import "DictionaryHelper.h"
|
||||
#import "TwitterSearchClient.h"
|
||||
#import "AsyncCell.h"
|
||||
|
||||
@implementation AsyncCellImagesExample
|
||||
@@ -113,18 +112,14 @@
|
||||
|
||||
[SVProgressHUD showInView:self.view];
|
||||
|
||||
NSURLRequest *request = [self requestWithURL:@"http://search.twitter.com/search.json?q=%23ios"];
|
||||
[self jsonRequest:request
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
[SVProgressHUD dismiss];
|
||||
|
||||
self.results = [JSON arrayForKey:@"results"];
|
||||
[table reloadData];
|
||||
}
|
||||
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}
|
||||
];
|
||||
[[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"iOS" forKey:@"q"] success:^(id object) {
|
||||
[SVProgressHUD dismiss];
|
||||
|
||||
self.results = [object valueForKey:@"results"];
|
||||
[table reloadData];
|
||||
} failure:^(NSHTTPURLResponse *response, NSError *error) {
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AsyncImageExample : BaseViewController
|
||||
@interface AsyncImageExample : UIViewController
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UIImageView* imageView;
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
//
|
||||
|
||||
#import "AsyncImageExample.h"
|
||||
#import "ImageManager.h"
|
||||
|
||||
#import "UIImageView+AFNetworking.h"
|
||||
|
||||
@implementation AsyncImageExample
|
||||
|
||||
@@ -68,11 +69,7 @@
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
NSString* url = @"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Zaragoza_shel.JPG/266px-Zaragoza_shel.JPG";
|
||||
[ImageManager loadImage:url success:^(UIImage* img) {
|
||||
imageView.image = img;
|
||||
}];
|
||||
|
||||
[self.imageView setImageWithURL:[NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Zaragoza_shel.JPG/266px-Zaragoza_shel.JPG"]];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AutocompleteLocationExample : BaseViewController
|
||||
@interface AutocompleteLocationExample : UIViewController
|
||||
|
||||
@property (nonatomic, retain) NSMutableArray* suggestions;
|
||||
@property (nonatomic, retain) IBOutlet UILabel* label;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#import "AutocompleteLocationExample.h"
|
||||
#import "StringHelper.h"
|
||||
#import "JSONKit.h"
|
||||
#import "AFJSONRequestOperation.h"
|
||||
#import <MapKit/MapKit.h>
|
||||
|
||||
@implementation AutocompleteLocationExample
|
||||
@@ -131,47 +132,46 @@
|
||||
// You could limit the search to a region (e.g. a country) by appending more text to the query
|
||||
// example: query = [NSString stringWithFormat:@"%@, Spain", text];
|
||||
NSString *urlEncode = [query urlEncode];
|
||||
NSString* u = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&hl=%@&oe=UTF8", urlEncode, [[NSLocale currentLocale] localeIdentifier]];
|
||||
NSURLRequest *request = [self requestWithURL:u];
|
||||
[self jsonRequest:request
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
NSLog(@"success");
|
||||
NSMutableArray* sug = [[NSMutableArray alloc] init];
|
||||
|
||||
NSArray* placemarks = [JSON objectForKey:@"Placemark"];
|
||||
|
||||
for (NSDictionary* placemark in placemarks) {
|
||||
NSString* address = [placemark objectForKey:@"address"];
|
||||
|
||||
NSDictionary* point = [placemark objectForKey:@"Point"];
|
||||
NSArray* coordinates = [point objectForKey:@"coordinates"];
|
||||
NSNumber* lon = [coordinates objectAtIndex:0];
|
||||
NSNumber* lat = [coordinates objectAtIndex:1];
|
||||
|
||||
MKPointAnnotation* place = [[MKPointAnnotation alloc] init];
|
||||
place.title = address;
|
||||
CLLocationCoordinate2D c = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]);
|
||||
place.coordinate = c;
|
||||
[sug addObject:place];
|
||||
[place release];
|
||||
}
|
||||
|
||||
self.suggestions = sug;
|
||||
[sug release];
|
||||
|
||||
[self.searchDisplayController.searchResultsTableView reloadData];
|
||||
loading = NO;
|
||||
|
||||
if (dirty) {
|
||||
dirty = NO;
|
||||
[self loadSearchSuggestions];
|
||||
}
|
||||
}
|
||||
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
NSLog(@"failure %@", [error localizedDescription]);
|
||||
loading = NO;
|
||||
}
|
||||
];
|
||||
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&hl=%@&oe=UTF8", urlEncode, [[NSLocale currentLocale] localeIdentifier]];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
|
||||
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
NSLog(@"success");
|
||||
NSMutableArray* sug = [[NSMutableArray alloc] init];
|
||||
|
||||
NSArray* placemarks = [JSON objectForKey:@"Placemark"];
|
||||
|
||||
for (NSDictionary* placemark in placemarks) {
|
||||
NSString* address = [placemark objectForKey:@"address"];
|
||||
|
||||
NSDictionary* point = [placemark objectForKey:@"Point"];
|
||||
NSArray* coordinates = [point objectForKey:@"coordinates"];
|
||||
NSNumber* lon = [coordinates objectAtIndex:0];
|
||||
NSNumber* lat = [coordinates objectAtIndex:1];
|
||||
|
||||
MKPointAnnotation* place = [[MKPointAnnotation alloc] init];
|
||||
place.title = address;
|
||||
CLLocationCoordinate2D c = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]);
|
||||
place.coordinate = c;
|
||||
[sug addObject:place];
|
||||
[place release];
|
||||
}
|
||||
|
||||
self.suggestions = sug;
|
||||
[sug release];
|
||||
|
||||
[self.searchDisplayController.searchResultsTableView reloadData];
|
||||
loading = NO;
|
||||
|
||||
if (dirty) {
|
||||
dirty = NO;
|
||||
[self loadSearchSuggestions];
|
||||
}
|
||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
NSLog(@"failure %@", [error localizedDescription]);
|
||||
loading = NO;
|
||||
}];
|
||||
[operation start];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// BaseViewController.h
|
||||
//
|
||||
// Copyright (c) 2011 Alberto Gimeno Brieba
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AFJSONRequestOperation.h"
|
||||
#import "AFXMLRequestOperation.h"
|
||||
#import "AFImageRequestOperation.h"
|
||||
#import "AFHTTPRequestOperation.h"
|
||||
|
||||
@interface BaseViewController : UIViewController {
|
||||
|
||||
NSMutableArray* requests;
|
||||
NSOperationQueue *queue;
|
||||
|
||||
}
|
||||
|
||||
- (void) queueOperation:(NSOperation*)operation;
|
||||
- (void) cancelOperations;
|
||||
|
||||
- (NSURLRequest*) requestWithURL:(NSString*)urlString;
|
||||
- (NSMutableURLRequest*) mutableRequestWithURL:(NSString*)urlString;
|
||||
|
||||
- (AFHTTPRequestOperation *)simpleRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(id object))success
|
||||
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure;
|
||||
|
||||
- (AFImageRequestOperation*) imageRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(UIImage *image))success;
|
||||
|
||||
- (AFJSONRequestOperation*) jsonRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
||||
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
||||
|
||||
- (AFXMLRequestOperation*) xmlRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
|
||||
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
||||
|
||||
@end
|
||||
@@ -1,113 +0,0 @@
|
||||
//
|
||||
// BaseViewController.m
|
||||
//
|
||||
// Copyright (c) 2011 Alberto Gimeno Brieba
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import "IOSBoilerplateAppDelegate.h"
|
||||
|
||||
@implementation BaseViewController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark HTTP requests
|
||||
|
||||
- (NSURLRequest*) requestWithURL:(NSString*)urlString {
|
||||
return [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
}
|
||||
|
||||
- (NSMutableURLRequest*) mutableRequestWithURL:(NSString*)urlString {
|
||||
return [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
}
|
||||
|
||||
- (AFImageRequestOperation*) imageRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(UIImage *image))success {
|
||||
|
||||
AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:urlRequest success:success];
|
||||
[self queueOperation:operation];
|
||||
return operation;
|
||||
}
|
||||
|
||||
- (AFJSONRequestOperation*) jsonRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
||||
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure {
|
||||
|
||||
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:urlRequest success:success failure:failure];
|
||||
operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
|
||||
[self queueOperation:operation];
|
||||
return operation;
|
||||
}
|
||||
|
||||
- (AFXMLRequestOperation*) xmlRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
|
||||
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure {
|
||||
|
||||
AFXMLRequestOperation* operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:urlRequest success:success failure:failure];
|
||||
[self queueOperation:operation];
|
||||
return operation;
|
||||
}
|
||||
|
||||
- (AFHTTPRequestOperation *)simpleRequest:(NSURLRequest *)urlRequest
|
||||
success:(void (^)(id object))success
|
||||
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure {
|
||||
AFHTTPRequestOperation* operation = [AFHTTPRequestOperation HTTPRequestOperationWithRequest:urlRequest success:success failure:failure];
|
||||
[self queueOperation:operation];
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
||||
- (void) queueOperation:(NSOperation*)operation {
|
||||
if (!queue) {
|
||||
queue = [[NSOperationQueue alloc] init];
|
||||
}
|
||||
[queue addOperation:operation];
|
||||
}
|
||||
|
||||
- (void) cancelOperations {
|
||||
[queue cancelAllOperations];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark UIViewController
|
||||
|
||||
- (void) viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (void) viewDidUnload {
|
||||
[super viewDidUnload];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)dealloc {
|
||||
[self cancelOperations];
|
||||
[requests release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -26,10 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <MapKit/MapKit.h>
|
||||
|
||||
@interface DirectionsExample : BaseViewController
|
||||
@interface DirectionsExample : UIViewController
|
||||
|
||||
@property(nonatomic, retain) id<MKAnnotation> source;
|
||||
@property(nonatomic, retain) id<MKAnnotation> destination;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#import "DirectionsExample.h"
|
||||
#import "StringHelper.h"
|
||||
#import "AFHTTPRequestOperation.h"
|
||||
|
||||
@implementation DirectionsExample
|
||||
|
||||
@@ -144,50 +145,45 @@
|
||||
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
|
||||
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];
|
||||
|
||||
NSString* s = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];
|
||||
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];
|
||||
// by car:
|
||||
// s = [s stringByAppendingFormat:@"&dirflg=w"];
|
||||
NSURLRequest *request = [self requestWithURL:s];
|
||||
// urlString = [urlString stringByAppendingFormat:@"&dirflg=w"];
|
||||
|
||||
|
||||
[self simpleRequest:request
|
||||
success:^(id object) {
|
||||
@try {
|
||||
NSData* data = object;
|
||||
NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
|
||||
// TODO: better parsing. Regular expression?
|
||||
|
||||
NSInteger a = [responseString indexOf:@"points:\"" from:0];
|
||||
NSInteger b = [responseString indexOf:@"\",levels:\"" from:a] - 10;
|
||||
|
||||
NSInteger c = [responseString indexOf:@"tooltipHtml:\"" from:0];
|
||||
NSInteger d = [responseString indexOf:@"(" from:c];
|
||||
NSInteger e = [responseString indexOf:@")\"" from:d] - 2;
|
||||
|
||||
NSString* info = [[responseString substringFrom:d to:e] stringByReplacingOccurrencesOfString:@"\\x26#160;" withString:@""];
|
||||
NSLog(@"tooltip %@", info);
|
||||
|
||||
NSString* encodedPoints = [responseString substringFrom:a to:b];
|
||||
NSArray* steps = [self decodePolyLine:[encodedPoints mutableCopy]];
|
||||
if (steps && [steps count] > 0) {
|
||||
[self setRoutePoints:steps];
|
||||
//} else if (!steps) {
|
||||
// [self showError:@"No se pudo calcular la ruta"];
|
||||
} else {
|
||||
// TODO: show error
|
||||
}
|
||||
|
||||
[responseString release];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
// TODO: show error
|
||||
}
|
||||
}
|
||||
failure:^(NSHTTPURLResponse *response, NSError *error) {
|
||||
// TODO: show error
|
||||
}
|
||||
];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
|
||||
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||
operation.completionBlock = ^ {
|
||||
@try {
|
||||
NSData* data = operation.responseData;
|
||||
NSString* responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
|
||||
// TODO: better parsing. Regular expression?
|
||||
|
||||
NSInteger a = [responseString indexOf:@"points:\"" from:0];
|
||||
NSInteger b = [responseString indexOf:@"\",levels:\"" from:a] - 10;
|
||||
|
||||
NSInteger c = [responseString indexOf:@"tooltipHtml:\"" from:0];
|
||||
NSInteger d = [responseString indexOf:@"(" from:c];
|
||||
NSInteger e = [responseString indexOf:@")\"" from:d] - 2;
|
||||
|
||||
NSString* info = [[responseString substringFrom:d to:e] stringByReplacingOccurrencesOfString:@"\\x26#160;" withString:@""];
|
||||
NSLog(@"tooltip %@", info);
|
||||
|
||||
NSString* encodedPoints = [responseString substringFrom:a to:b];
|
||||
NSArray* steps = [self decodePolyLine:[encodedPoints mutableCopy]];
|
||||
if (steps && [steps count] > 0) {
|
||||
[self setRoutePoints:steps];
|
||||
//} else if (!steps) {
|
||||
// [self showError:@"No se pudo calcular la ruta"];
|
||||
} else {
|
||||
// TODO: show error
|
||||
}
|
||||
|
||||
[responseString release];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
// TODO: show error
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
NSString* s = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@&hl=%@", saddr, daddr, [[NSLocale currentLocale] localeIdentifier]];
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface HTTPHUDExample : BaseViewController {
|
||||
|
||||
@interface HTTPHUDExample : UIViewController {
|
||||
NSOperationQueue *_requestOperationQueue;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UILabel* label;
|
||||
|
||||
@@ -32,15 +32,20 @@
|
||||
#import "DictionaryHelper.h"
|
||||
#import "AFJSONRequestOperation.h"
|
||||
|
||||
@interface HTTPHUDExample ()
|
||||
@property (readwrite, nonatomic, retain) NSOperationQueue *requestOperationQueue;
|
||||
@end
|
||||
|
||||
@implementation HTTPHUDExample
|
||||
|
||||
@synthesize label;
|
||||
@synthesize requestOperationQueue = _requestOperationQueue;
|
||||
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
||||
{
|
||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||
if (self) {
|
||||
// Custom initialization
|
||||
self.requestOperationQueue = [[[NSOperationQueue alloc] init] autorelease];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -78,17 +83,15 @@
|
||||
|
||||
[SVProgressHUD showInView:self.view];
|
||||
|
||||
NSURLRequest *request = [self requestWithURL:@"http://api.twitter.com/1/statuses/show.json?id=125372508387024896&include_entities=false"];
|
||||
[self jsonRequest:request
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
label.text = [JSON valueForKeyPath:@"text"];
|
||||
[SVProgressHUD dismissWithSuccess:@"Ok!"];
|
||||
}
|
||||
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
label.text = @"error";
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}
|
||||
];
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/show.json?id=125372508387024896&include_entities=false"]];
|
||||
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
label.text = [JSON valueForKeyPath:@"text"];
|
||||
[SVProgressHUD dismissWithSuccess:@"Ok!"];
|
||||
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
label.text = @"error";
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}];
|
||||
[operation start];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
//
|
||||
|
||||
#import "IOSBoilerplateAppDelegate.h"
|
||||
#import "ImageManager.h"
|
||||
#import "AFURLCache.h"
|
||||
#import "BrowserViewController.h"
|
||||
|
||||
@@ -100,11 +99,10 @@
|
||||
Save data if appropriate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
[ImageManager releaseSingleton];
|
||||
}
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
[ImageManager clearMemoryCache];
|
||||
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// ImageManager.h
|
||||
// IOSBoilerplate
|
||||
//
|
||||
// Copyright (c) 2011 Alberto Gimeno Brieba
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ImageManager : NSObject {
|
||||
|
||||
NSOperationQueue *downloadQueue;
|
||||
|
||||
}
|
||||
|
||||
+ (void)loadImage:(NSString*)url success:(void (^)(UIImage *image))success;
|
||||
- (void)loadImage:(NSString*)url success:(void (^)(UIImage *image))success;
|
||||
|
||||
+ (void) clearMemoryCache;
|
||||
- (void) clearMemoryCache;
|
||||
|
||||
+ (void) clearCache;
|
||||
- (void) clearCache;
|
||||
|
||||
- (NSString*) cacheDirectory;
|
||||
|
||||
+ (void) releaseSingleton;
|
||||
|
||||
@end
|
||||
@@ -1,113 +0,0 @@
|
||||
//
|
||||
// ImageManager.m
|
||||
// IOSBoilerplate
|
||||
//
|
||||
// Copyright (c) 2011 Alberto Gimeno Brieba
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "ImageManager.h"
|
||||
#import "IOSBoilerplateAppDelegate.h"
|
||||
#import "AFImageRequestOperation.h"
|
||||
#import "AFImageCache.h"
|
||||
|
||||
@implementation ImageManager
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
downloadQueue = [[NSOperationQueue alloc] init];
|
||||
[downloadQueue setMaxConcurrentOperationCount:3];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[downloadQueue release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
static ImageManager *sharedSingleton;
|
||||
|
||||
+ (void)initialize {
|
||||
static BOOL initialized = NO;
|
||||
if(!initialized) {
|
||||
initialized = YES;
|
||||
sharedSingleton = [[ImageManager alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
// Future use
|
||||
- (NSString*) cacheDirectory {
|
||||
return [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/images/"];
|
||||
}
|
||||
|
||||
- (void)loadImage:(NSString*)url success:(void (^)(UIImage *image))success {
|
||||
static NSString* cacheName = nil;
|
||||
|
||||
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
|
||||
request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
|
||||
UIImage *image = [[AFImageCache sharedImageCache] cachedImageForURL:request.URL cacheName:cacheName];
|
||||
if (image) {
|
||||
success(image);
|
||||
} else {
|
||||
AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:nil cacheName:cacheName success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
|
||||
success(image);
|
||||
} failure:nil];
|
||||
|
||||
[downloadQueue addOperation:operation];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)loadImage:(NSString*)url success:(void (^)(UIImage *image))success {
|
||||
[sharedSingleton loadImage:url success:success];
|
||||
}
|
||||
|
||||
+ (void) clearMemoryCache {
|
||||
[sharedSingleton clearMemoryCache];
|
||||
}
|
||||
|
||||
- (void) clearMemoryCache {
|
||||
[[AFImageCache sharedImageCache] removeAllObjects];
|
||||
}
|
||||
|
||||
+ (void) clearCache {
|
||||
[sharedSingleton clearCache];
|
||||
}
|
||||
|
||||
- (void) clearCache {
|
||||
NSFileManager* fs = [NSFileManager defaultManager];
|
||||
// BOOL b =
|
||||
[fs removeItemAtPath:[self cacheDirectory] error:NULL];
|
||||
|
||||
}
|
||||
|
||||
+ (void) releaseSingleton {
|
||||
[sharedSingleton release];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -26,10 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import "EGORefreshTableHeaderView.h"
|
||||
|
||||
@interface ListViewController : BaseViewController<EGORefreshTableHeaderDelegate> {
|
||||
@interface ListViewController : UIViewController <EGORefreshTableHeaderDelegate> {
|
||||
|
||||
EGORefreshTableHeaderView *_refreshHeaderView;
|
||||
BOOL _reloading;
|
||||
|
||||
@@ -27,9 +27,8 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
@interface RootViewController : BaseViewController <UITableViewDelegate, UITableViewDataSource> {
|
||||
@interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface SwipeableTableViewExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
@interface SwipeableTableViewExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UITableView* table;
|
||||
|
||||
|
||||
14
IOSBoilerplate/TwitterSearchClient.h
Normal file
14
IOSBoilerplate/TwitterSearchClient.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// TwitterSearchClient.h
|
||||
// IOSBoilerplate
|
||||
//
|
||||
// Created by Mattt Thompson on 11/10/31.
|
||||
// Copyright (c) 2011年 Gowalla. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AFHTTPClient.h"
|
||||
|
||||
@interface TwitterSearchClient : AFHTTPClient
|
||||
+ (TwitterSearchClient *)sharedClient;
|
||||
@end
|
||||
47
IOSBoilerplate/TwitterSearchClient.m
Normal file
47
IOSBoilerplate/TwitterSearchClient.m
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// TwitterSearchClient.m
|
||||
// IOSBoilerplate
|
||||
//
|
||||
// Created by Mattt Thompson on 11/10/31.
|
||||
// Copyright (c) 2011年 Gowalla. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TwitterSearchClient.h"
|
||||
|
||||
#import "AFJSONRequestOperation.h"
|
||||
|
||||
NSString * const kTwitterBaseURLString = @"https://search.twitter.com/";
|
||||
|
||||
|
||||
@implementation TwitterSearchClient
|
||||
|
||||
+ (TwitterSearchClient *)sharedClient {
|
||||
static TwitterSearchClient *_sharedClient = nil;
|
||||
static dispatch_once_t oncePredicate;
|
||||
dispatch_once(&oncePredicate, ^{
|
||||
_sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kTwitterBaseURLString]];
|
||||
});
|
||||
|
||||
return _sharedClient;
|
||||
}
|
||||
|
||||
- (id)initWithBaseURL:(NSURL *)url {
|
||||
self = [super initWithBaseURL:url];
|
||||
if (!self) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||
|
||||
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
[self setDefaultHeader:@"Accept" value:@"application/json"];
|
||||
|
||||
// X-UDID HTTP Header
|
||||
[self setDefaultHeader:@"X-UDID" value:[[UIDevice currentDevice] uniqueIdentifier]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -27,7 +27,6 @@
|
||||
//
|
||||
|
||||
#import "VariableHeightCell.h"
|
||||
#import "ImageManager.h"
|
||||
#import "DictionaryHelper.h"
|
||||
|
||||
@implementation VariableHeightCell
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import "BaseViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface VariableHeightExample : BaseViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
@interface VariableHeightExample : UIViewController <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UITableView* table;
|
||||
@property (nonatomic, retain) NSArray* results;
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
|
||||
#import "VariableHeightExample.h"
|
||||
#import "SVProgressHUD.h"
|
||||
#import "JSONKit.h"
|
||||
#import "DictionaryHelper.h"
|
||||
#import "TwitterSearchClient.h"
|
||||
#import "VariableHeightCell.h"
|
||||
|
||||
@implementation VariableHeightExample
|
||||
@@ -110,18 +109,14 @@
|
||||
|
||||
[SVProgressHUD showInView:self.view];
|
||||
|
||||
NSURLRequest *request = [self requestWithURL:@"http://search.twitter.com/search.json?q=%23cats"];
|
||||
[self jsonRequest:request
|
||||
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
|
||||
[SVProgressHUD dismiss];
|
||||
|
||||
self.results = [JSON arrayForKey:@"results"];
|
||||
[table reloadData];
|
||||
}
|
||||
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}
|
||||
];
|
||||
[[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"cats" forKey:@"q"] success:^(id object) {
|
||||
[SVProgressHUD dismiss];
|
||||
|
||||
self.results = [object valueForKey:@"results"];
|
||||
[table reloadData];
|
||||
} failure:^(NSHTTPURLResponse *response, NSError *error) {
|
||||
[SVProgressHUD dismissWithError:[error localizedDescription]];
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
|
||||
Reference in New Issue
Block a user