Ben Copsey

Starting point for new iPhone and iPad sample app

@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 23
24 24
25 // Automatically set on build 25 // Automatically set on build
26 -NSString *ASIHTTPRequestVersion = @"v1.6.2-16 2010-06-15"; 26 +NSString *ASIHTTPRequestVersion = @"v1.6.2-17 2010-06-17";
27 27
28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 28 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
29 29
1 // 1 //
2 // AuthenticationViewController.h 2 // AuthenticationViewController.h
3 -// iPhone 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 01/08/2009. 5 // Created by Ben Copsey on 01/08/2009.
6 // Copyright 2009 All-Seeing Interactive. All rights reserved. 6 // Copyright 2009 All-Seeing Interactive. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
  10 +#import "SampleViewController.h"
10 @class ASIHTTPRequest; 11 @class ASIHTTPRequest;
11 12
12 -@interface AuthenticationViewController : UIViewController { 13 +@interface AuthenticationViewController : SampleViewController {
13 - IBOutlet UISwitch *useKeychain; 14 +
14 - IBOutlet UISwitch *useBuiltInDialog; 15 + ASIHTTPRequest *request;
15 - IBOutlet UILabel *topSecretInfo; 16 +
16 - ASIHTTPRequest *requestRequiringAuthentication; 17 + UISwitch *useKeychain;
17 - ASIHTTPRequest *requestRequiringProxyAuthentication; 18 + UISwitch *useBuiltInDialog;
  19 + UITextView *responseField;
18 } 20 }
19 - (IBAction)fetchTopSecretInformation:(id)sender; 21 - (IBAction)fetchTopSecretInformation:(id)sender;
20 22
21 -@property (retain) ASIHTTPRequest *requestRequiringAuthentication; 23 +@property (retain, nonatomic) ASIHTTPRequest *request;
22 -@property (retain) ASIHTTPRequest *requestRequiringProxyAuthentication;  
23 @end 24 @end
1 // 1 //
2 // AuthenticationViewController.m 2 // AuthenticationViewController.m
3 -// iPhone 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 01/08/2009. 5 // Created by Ben Copsey on 01/08/2009.
6 // Copyright 2009 All-Seeing Interactive. All rights reserved. 6 // Copyright 2009 All-Seeing Interactive. All rights reserved.
@@ -8,12 +8,15 @@ @@ -8,12 +8,15 @@
8 8
9 #import "AuthenticationViewController.h" 9 #import "AuthenticationViewController.h"
10 #import "ASIHTTPRequest.h" 10 #import "ASIHTTPRequest.h"
  11 +#import "InfoCell.h"
  12 +#import "DetailCell.h"
  13 +#import "ToggleCell.h"
11 14
12 @implementation AuthenticationViewController 15 @implementation AuthenticationViewController
13 16
14 - (IBAction)fetchTopSecretInformation:(id)sender 17 - (IBAction)fetchTopSecretInformation:(id)sender
15 { 18 {
16 - ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]]; 19 + [self setRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]]];
17 [request setUseKeychainPersistence:[useKeychain isOn]]; 20 [request setUseKeychainPersistence:[useKeychain isOn]];
18 [request setDelegate:self]; 21 [request setDelegate:self];
19 [request setShouldPresentAuthenticationDialog:[useBuiltInDialog isOn]]; 22 [request setShouldPresentAuthenticationDialog:[useBuiltInDialog isOn]];
@@ -23,25 +26,20 @@ @@ -23,25 +26,20 @@
23 26
24 } 27 }
25 28
26 -- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)request 29 +- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest
27 { 30 {
28 - [topSecretInfo setText:[[request error] localizedDescription]]; 31 + [responseField setText:[[request error] localizedDescription]];
29 - [topSecretInfo setFont:[UIFont boldSystemFontOfSize:12]]; 32 + [responseField setFont:[UIFont boldSystemFontOfSize:12]];
30 } 33 }
31 34
32 -- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)request 35 +- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest
33 { 36 {
34 - [topSecretInfo setText:[request responseString]]; 37 + [responseField setText:[request responseString]];
35 - [topSecretInfo setFont:[UIFont boldSystemFontOfSize:12]]; 38 + [responseField setFont:[UIFont boldSystemFontOfSize:12]];
36 } 39 }
37 40
38 -- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request 41 +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)theRequest
39 { 42 {
40 - // Why oh why is there no contextInfo for alertView like on Mac OS ?!  
41 - [self setRequestRequiringProxyAuthentication:nil];  
42 - [self setRequestRequiringAuthentication:request];  
43 -  
44 -  
45 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease]; 43 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
46 // These are undocumented, use at your own risk! 44 // These are undocumented, use at your own risk!
47 // A better general approach would be to subclass UIAlertView, or just use ASIHTTPRequest's built-in dialog 45 // A better general approach would be to subclass UIAlertView, or just use ASIHTTPRequest's built-in dialog
@@ -51,10 +49,8 @@ @@ -51,10 +49,8 @@
51 49
52 } 50 }
53 51
54 -- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request 52 +- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)theRequest
55 { 53 {
56 - [self setRequestRequiringAuthentication:nil];  
57 - [self setRequestRequiringProxyAuthentication:request];  
58 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease]; 54 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
59 [alertView addTextFieldWithValue:@"" label:@"Username"]; 55 [alertView addTextFieldWithValue:@"" label:@"Username"];
60 [alertView addTextFieldWithValue:@"" label:@"Password"]; 56 [alertView addTextFieldWithValue:@"" label:@"Password"];
@@ -66,17 +62,17 @@ @@ -66,17 +62,17 @@
66 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 62 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
67 { 63 {
68 if (buttonIndex == 1) { 64 if (buttonIndex == 1) {
69 - if ([self requestRequiringAuthentication]) { 65 + if ([[self request] authenticationNeeded] == ASIHTTPAuthenticationNeeded) {
70 - [[self requestRequiringAuthentication] setUsername:[[alertView textFieldAtIndex:0] text]]; 66 + [[self request] setUsername:[[alertView textFieldAtIndex:0] text]];
71 - [[self requestRequiringAuthentication] setPassword:[[alertView textFieldAtIndex:1] text]]; 67 + [[self request] setPassword:[[alertView textFieldAtIndex:1] text]];
72 - [[self requestRequiringAuthentication] retryUsingSuppliedCredentials]; 68 + [[self request] retryUsingSuppliedCredentials];
73 - } else if ([self requestRequiringProxyAuthentication]) { 69 + } else if ([[self request] authenticationNeeded] == ASIProxyAuthenticationNeeded) {
74 - [[self requestRequiringProxyAuthentication] setProxyUsername:[[alertView textFieldAtIndex:0] text]]; 70 + [[self request] setProxyUsername:[[alertView textFieldAtIndex:0] text]];
75 - [[self requestRequiringProxyAuthentication] setProxyPassword:[[alertView textFieldAtIndex:1] text]]; 71 + [[self request] setProxyPassword:[[alertView textFieldAtIndex:1] text]];
76 - [[self requestRequiringProxyAuthentication] retryUsingSuppliedCredentials]; 72 + [[self request] retryUsingSuppliedCredentials];
77 } 73 }
78 } else { 74 } else {
79 - [[self requestRequiringAuthentication] cancelAuthentication]; 75 + [[self request] cancelAuthentication];
80 } 76 }
81 } 77 }
82 78
@@ -99,11 +95,131 @@ @@ -99,11 +95,131 @@
99 95
100 - (void)dealloc 96 - (void)dealloc
101 { 97 {
102 - [requestRequiringAuthentication release]; 98 + [request cancel];
103 - [requestRequiringProxyAuthentication release]; 99 + [request release];
104 [super dealloc]; 100 [super dealloc];
105 } 101 }
106 102
107 -@synthesize requestRequiringAuthentication; 103 +/*
108 -@synthesize requestRequiringProxyAuthentication; 104 + Most of the code below here relates to the table view, and isn't that interesting
  105 + */
  106 +
  107 +- (void)viewDidLoad
  108 +{
  109 + [[[self navigationBar] topItem] setTitle:@"HTTP Authentication"];
  110 +}
  111 +
  112 +static NSString *intro = @"Demonstrates fetching content from an area that requires HTTP authentication. You will be prompted for a username and password, enter 'topsecret' for both.\nIf you turn on keychain support, successful authentication will result in the username and password you provided being stored in your keychain. The application will use these details rather than prompt you the next time.\nToggle 'Use built-in dialog' to switch between ASIHTTPRequest's built-in dialog, and one created by the delegate.";
  113 +
  114 +- (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInteger)section
  115 +{
  116 + if (section == 1) {
  117 + int tablePadding = 40;
  118 + int tableWidth = [tableView frame].size.width;
  119 + if (tableWidth > 480) { // iPad
  120 + tablePadding = 110;
  121 + }
  122 +
  123 + UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0,0,tableWidth-(tablePadding/2),30)] autorelease];
  124 + UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  125 + [goButton setTitle:@"Go!" forState:UIControlStateNormal];
  126 + [goButton sizeToFit];
  127 + [goButton setFrame:CGRectMake([view frame].size.width-[goButton frame].size.width+10,7,[goButton frame].size.width,[goButton frame].size.height)];
  128 +
  129 + [goButton addTarget:self action:@selector(fetchTopSecretInformation:) forControlEvents:UIControlEventTouchDown];
  130 + [view addSubview:goButton];
  131 +
  132 + return view;
  133 + }
  134 + return nil;
  135 +}
  136 +
  137 +- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  138 +{
  139 + UITableViewCell *cell;
  140 + if ([indexPath section] == 0) {
  141 + cell = [InfoCell cellWithDescription:intro];
  142 + } else if ([indexPath section] == 1) {
  143 + cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
  144 + if (!cell) {
  145 + cell = [ToggleCell cell];
  146 + }
  147 + } else {
  148 + cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
  149 + if (!cell) {
  150 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
  151 + }
  152 + }
  153 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  154 +
  155 + int tablePadding = 40;
  156 + int tableWidth = [tableView frame].size.width;
  157 + if (tableWidth > 480) { // iPad
  158 + tablePadding = 110;
  159 + }
  160 +
  161 + switch ([indexPath section]) {
  162 + case 1:
  163 + switch ([indexPath row]) {
  164 + case 0:
  165 + [[cell textLabel] setText:@"Use Keychain"];
  166 + useKeychain = [(ToggleCell *)cell toggle];
  167 + break;
  168 + case 1:
  169 + [[cell textLabel] setText:@"Use Built-In Dialog"];
  170 + useBuiltInDialog = [(ToggleCell *)cell toggle];
  171 + break;
  172 + }
  173 + break;
  174 + case 2:
  175 + responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease];
  176 + [responseField setBackgroundColor:[UIColor clearColor]];
  177 + [responseField setText:@"Secret information will appear here if authentication succeeds"];
  178 + [[cell contentView] addSubview:responseField];
  179 + break;
  180 + }
  181 + return cell;
  182 +}
  183 +
  184 +- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
  185 +{
  186 + if (section == 1) {
  187 + return 2;
  188 + } else {
  189 + return 1;
  190 + }
  191 +}
  192 +
  193 +- (CGFloat)tableView:(UITableView *)theTableView heightForHeaderInSection:(NSInteger)section
  194 +{
  195 + if (section == 1) {
  196 + return 50;
  197 + }
  198 + return 34;
  199 +}
  200 +
  201 +- (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  202 +{
  203 + if ([indexPath section] == 0) {
  204 + return [InfoCell neededHeightForDescription:intro withTableWidth:[tableView frame].size.width]+20;
  205 + } else if ([indexPath section] == 2) {
  206 + return 160;
  207 + } else {
  208 + return 42;
  209 + }
  210 +}
  211 +
  212 +- (NSString *)tableView:(UITableView *)theTableView titleForHeaderInSection:(NSInteger)section
  213 +{
  214 +
  215 + return nil;
  216 +}
  217 +
  218 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  219 +{
  220 + return 3;
  221 +}
  222 +
  223 +
  224 +@synthesize request;
109 @end 225 @end
  1 +//
  2 +// DetailCell.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 16/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +
  12 +@interface DetailCell : UITableViewCell {
  13 +
  14 +}
  15 ++ (id)cell;
  16 +
  17 +@end
  1 +//
  2 +// DetailCell.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 16/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "DetailCell.h"
  10 +
  11 +
  12 +@implementation DetailCell
  13 +
  14 ++ (id)cell
  15 +{
  16 + DetailCell *cell = [[[DetailCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"HeaderCell"] autorelease];
  17 + [[cell detailTextLabel] setTextAlignment:UITextAlignmentLeft];
  18 + [[cell detailTextLabel] setFont:[UIFont systemFontOfSize:14]];
  19 + return cell;
  20 +}
  21 +
  22 +- (void)layoutSubviews
  23 +{
  24 + [super layoutSubviews];
  25 + int tablePadding = 40;
  26 + int tableWidth = [[self superview] frame].size.width;
  27 + if (tableWidth > 480) { // iPad
  28 + tablePadding = 110;
  29 + }
  30 + [[self textLabel] setFrame:CGRectMake(5,5,120,20)];
  31 + [[self detailTextLabel] setFrame:CGRectMake(135,5,[self frame].size.width-145-tablePadding,20)];
  32 +
  33 +}
  34 +
  35 +@end
  1 +//
  2 +// InfoCell.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +
  12 +@interface InfoCell : UITableViewCell {
  13 +
  14 +}
  15 ++ (id)cellWithDescription:(NSString *)description;
  16 ++ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth;
  17 +@end
  1 +//
  2 +// InfoCell.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "InfoCell.h"
  10 +
  11 +
  12 +@implementation InfoCell
  13 +
  14 ++ (id)cellWithDescription:(NSString *)description
  15 +{
  16 + InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease];
  17 + if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
  18 + [[cell textLabel] setFont:[UIFont systemFontOfSize:14]];
  19 + } else {
  20 + [[cell textLabel] setFont:[UIFont systemFontOfSize:13]];
  21 + }
  22 + [[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap];
  23 + [[cell textLabel] setNumberOfLines:0];
  24 + [[cell textLabel] setText:description];
  25 + [[cell textLabel] sizeToFit];
  26 +
  27 + if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
  28 + UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease];
  29 + [imageView setImage:[UIImage imageNamed:@"info.png"]];
  30 + [[cell contentView] addSubview:imageView];
  31 + }
  32 + return cell;
  33 +}
  34 +
  35 +- (void)layoutSubviews
  36 +{
  37 + [super layoutSubviews];
  38 + int tablePadding = 40;
  39 + int tableWidth = [[self superview] frame].size.width;
  40 + if (tableWidth > 480) { // iPad
  41 + tablePadding = 110;
  42 + [[self textLabel] setFrame:CGRectMake(70,10,tableWidth-tablePadding-70,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])];
  43 + } else {
  44 + [[self textLabel] setFrame:CGRectMake(10,10,tableWidth-tablePadding,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])];
  45 + }
  46 +
  47 +}
  48 +
  49 ++ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth
  50 +{
  51 + int tablePadding = 40;
  52 + int offset = 0;
  53 + int textSize = 13;
  54 + if (tableWidth > 480) { // iPad
  55 + tablePadding = 110;
  56 + offset = 70;
  57 + textSize = 14;
  58 + }
  59 + CGSize labelSize = [description sizeWithFont:[UIFont systemFontOfSize:textSize] constrainedToSize:CGSizeMake(tableWidth-tablePadding-offset,1000) lineBreakMode:UILineBreakModeWordWrap];
  60 + if (labelSize.height < 48) {
  61 + return 58;
  62 + }
  63 + return labelSize.height;
  64 +}
  65 +
  66 +@end
1 // 1 //
2 // QueueViewController.h 2 // QueueViewController.h
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
  10 +#import "SampleViewController.h"
10 11
11 @class ASINetworkQueue; 12 @class ASINetworkQueue;
12 13
13 -@interface QueueViewController : UIViewController { 14 +@interface QueueViewController : SampleViewController {
14 ASINetworkQueue *networkQueue; 15 ASINetworkQueue *networkQueue;
15 16
16 - IBOutlet UIImageView *imageView1; 17 + UIImageView *imageView1;
17 - IBOutlet UIImageView *imageView2; 18 + UIImageView *imageView2;
18 - IBOutlet UIImageView *imageView3; 19 + UIImageView *imageView3;
19 - IBOutlet UIProgressView *progressIndicator; 20 + UIProgressView *progressIndicator;
20 - IBOutlet UISwitch *accurateProgress; 21 + UISwitch *accurateProgress;
  22 + UIProgressView *imageProgressIndicator1;
  23 + UIProgressView *imageProgressIndicator2;
  24 + UIProgressView *imageProgressIndicator3;
  25 + BOOL failed;
21 26
22 } 27 }
23 28
1 // 1 //
2 // QueueViewController.m 2 // QueueViewController.m
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
@@ -9,38 +9,43 @@ @@ -9,38 +9,43 @@
9 #import "QueueViewController.h" 9 #import "QueueViewController.h"
10 #import "ASIHTTPRequest.h" 10 #import "ASIHTTPRequest.h"
11 #import "ASINetworkQueue.h" 11 #import "ASINetworkQueue.h"
  12 +#import "InfoCell.h"
  13 +#import "ToggleCell.h"
12 14
13 @implementation QueueViewController 15 @implementation QueueViewController
14 16
15 17
16 -- (void)awakeFromNib  
17 -{  
18 - networkQueue = [[ASINetworkQueue alloc] init];  
19 -}  
20 -  
21 - (IBAction)fetchThreeImages:(id)sender 18 - (IBAction)fetchThreeImages:(id)sender
22 { 19 {
23 [imageView1 setImage:nil]; 20 [imageView1 setImage:nil];
24 [imageView2 setImage:nil]; 21 [imageView2 setImage:nil];
25 [imageView3 setImage:nil]; 22 [imageView3 setImage:nil];
26 23
27 - [networkQueue cancelAllOperations]; 24 + if (!networkQueue) {
  25 + networkQueue = [[ASINetworkQueue alloc] init];
  26 + }
  27 + failed = NO;
  28 + [networkQueue reset];
28 [networkQueue setDownloadProgressDelegate:progressIndicator]; 29 [networkQueue setDownloadProgressDelegate:progressIndicator];
29 [networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)]; 30 [networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)];
  31 + [networkQueue setRequestDidFailSelector:@selector(imageFetchFailed:)];
30 [networkQueue setShowAccurateProgress:[accurateProgress isOn]]; 32 [networkQueue setShowAccurateProgress:[accurateProgress isOn]];
31 [networkQueue setDelegate:self]; 33 [networkQueue setDelegate:self];
32 34
33 ASIHTTPRequest *request; 35 ASIHTTPRequest *request;
34 request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]]; 36 request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
35 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]]; 37 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
  38 + [request setDownloadProgressDelegate:imageProgressIndicator1];
36 [networkQueue addOperation:request]; 39 [networkQueue addOperation:request];
37 40
38 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease]; 41 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease];
39 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]]; 42 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]];
  43 + [request setDownloadProgressDelegate:imageProgressIndicator2];
40 [networkQueue addOperation:request]; 44 [networkQueue addOperation:request];
41 45
42 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease]; 46 request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease];
43 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]]; 47 [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]];
  48 + [request setDownloadProgressDelegate:imageProgressIndicator3];
44 [networkQueue addOperation:request]; 49 [networkQueue addOperation:request];
45 50
46 [networkQueue go]; 51 [networkQueue go];
@@ -63,10 +68,182 @@ @@ -63,10 +68,182 @@
63 } 68 }
64 } 69 }
65 70
  71 +- (void)imageFetchFailed:(ASIHTTPRequest *)request
  72 +{
  73 + if (!failed) {
  74 + if ([[request error] domain] != NetworkRequestErrorDomain || [[request error] code] != ASIRequestCancelledErrorType) {
  75 + UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Download failed" message:@"Failed to download images" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
  76 + [alertView show];
  77 + }
  78 + failed = YES;
  79 + }
  80 +}
  81 +
66 - (void)dealloc { 82 - (void)dealloc {
  83 + [networkQueue reset];
67 [networkQueue release]; 84 [networkQueue release];
68 [super dealloc]; 85 [super dealloc];
69 } 86 }
70 87
71 88
  89 +/*
  90 + Most of the code below here relates to the table view, and isn't that interesting
  91 + */
  92 +
  93 +- (void)viewDidLoad
  94 +{
  95 + [[[self navigationBar] topItem] setTitle:@"Using a Queue"];
  96 +}
  97 +
  98 +static NSString *intro = @"Demonstrates a fetching 3 items at once, using an ASINetworkQueue to track progress.\r\nEach request has its own downloadProgressDelegate, and the queue has an additional downloadProgressDelegate to track overall progress.";
  99 +
  100 +- (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInteger)section
  101 +{
  102 + if (section == 1) {
  103 + int tablePadding = 40;
  104 + int tableWidth = [tableView frame].size.width;
  105 + if (tableWidth > 480) { // iPad
  106 + tablePadding = 110;
  107 + }
  108 +
  109 + UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0,0,tableWidth-(tablePadding/2),30)] autorelease];
  110 + UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  111 + [goButton setTitle:@"Go!" forState:UIControlStateNormal];
  112 + [goButton sizeToFit];
  113 + [goButton setFrame:CGRectMake([view frame].size.width-[goButton frame].size.width+10,7,[goButton frame].size.width,[goButton frame].size.height)];
  114 +
  115 + [goButton addTarget:self action:@selector(fetchThreeImages:) forControlEvents:UIControlEventTouchUpInside];
  116 + [view addSubview:goButton];
  117 +
  118 + progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease];
  119 + [view addSubview:progressIndicator];
  120 +
  121 + return view;
  122 + }
  123 + return nil;
  124 +}
  125 +
  126 +- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  127 +{
  128 + UITableViewCell *cell;
  129 + if ([indexPath section] == 0) {
  130 + cell = [InfoCell cellWithDescription:intro];
  131 + } else if ([indexPath section] == 1) {
  132 + cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
  133 + if (!cell) {
  134 + cell = [ToggleCell cell];
  135 + }
  136 + } else {
  137 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
  138 + }
  139 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  140 +
  141 + int tablePadding = 40;
  142 + int tableWidth = [tableView frame].size.width;
  143 + if (tableWidth > 480) { // iPad
  144 + tablePadding = 110;
  145 + }
  146 +
  147 + if ([indexPath section] == 1) {
  148 + [[cell textLabel] setText:@"Show Accurate Progress"];
  149 + accurateProgress = [(ToggleCell *)cell toggle];
  150 + } else if ([indexPath section] == 2) {
  151 +
  152 + NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
  153 + NSUInteger imageHeight = imageWidth*0.66;
  154 +
  155 + imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease];
  156 + [imageView1 setBackgroundColor:[UIColor grayColor]];
  157 + [cell addSubview:imageView1];
  158 +
  159 + imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease];
  160 + [cell addSubview:imageProgressIndicator1];
  161 +
  162 + UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease];
  163 + if (tableWidth > 480) {
  164 + [label setText:@"This image is 15KB in size"];
  165 + } else {
  166 + [label setText:@"Img size: 15KB"];
  167 + }
  168 + [label setTextAlignment:UITextAlignmentCenter];
  169 + [label setFont:[UIFont systemFontOfSize:11]];
  170 + [label setBackgroundColor:[UIColor clearColor]];
  171 + [cell addSubview:label];
  172 +
  173 + imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease];
  174 + [imageView2 setBackgroundColor:[UIColor grayColor]];
  175 + [cell addSubview:imageView2];
  176 +
  177 + imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease];
  178 + [cell addSubview:imageProgressIndicator2];
  179 +
  180 + label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease];
  181 + if (tableWidth > 480) {
  182 + [label setText:@"This image is 176KB in size"];
  183 + } else {
  184 + [label setText:@"Img size: 176KB"];
  185 + }
  186 + [label setTextAlignment:UITextAlignmentCenter];
  187 + [label setFont:[UIFont systemFontOfSize:11]];
  188 + [label setBackgroundColor:[UIColor clearColor]];
  189 + [cell addSubview:label];
  190 +
  191 + imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease];
  192 + [imageView3 setBackgroundColor:[UIColor grayColor]];
  193 + [cell addSubview:imageView3];
  194 +
  195 + imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease];
  196 + [cell addSubview:imageProgressIndicator3];
  197 +
  198 + label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease];
  199 + if (tableWidth > 480) {
  200 + [label setText:@"This image is 1.4MB in size"];
  201 + } else {
  202 + [label setText:@"Img size: 1.4MB"];
  203 + }
  204 + [label setTextAlignment:UITextAlignmentCenter];
  205 + [label setFont:[UIFont systemFontOfSize:11]];
  206 + [label setBackgroundColor:[UIColor clearColor]];
  207 + [cell addSubview:label];
  208 +
  209 + }
  210 + return cell;
  211 +}
  212 +
  213 +- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
  214 +{
  215 + return 1;
  216 +}
  217 +
  218 +- (CGFloat)tableView:(UITableView *)theTableView heightForHeaderInSection:(NSInteger)section
  219 +{
  220 + if (section == 1) {
  221 + return 50;
  222 + }
  223 + return 34;
  224 +}
  225 +
  226 +- (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  227 +{
  228 + if ([indexPath section] == 0) {
  229 + return [InfoCell neededHeightForDescription:intro withTableWidth:[tableView frame].size.width]+20;
  230 + } else if ([indexPath section] == 2) {
  231 + int tablePadding = 40;
  232 + int tableWidth = [tableView frame].size.width;
  233 + if (tableWidth > 480) { // iPad
  234 + tablePadding = 110;
  235 + }
  236 + NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
  237 + NSUInteger imageHeight = imageWidth*0.66;
  238 + return imageHeight+50;
  239 + } else {
  240 + return 42;
  241 + }
  242 +}
  243 +
  244 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  245 +{
  246 + return 3;
  247 +}
  248 +
72 @end 249 @end
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
  1 +//
  2 +// RootViewController.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 16/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface RootViewController : UITableViewController <UISplitViewControllerDelegate> {
  12 + UISplitViewController *splitViewController;
  13 + UIPopoverController *popoverController;
  14 + UIBarButtonItem *rootPopoverButtonItem;
  15 +}
  16 +@property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;
  17 +@property (nonatomic, retain) UIPopoverController *popoverController;
  18 +@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
  19 +@end
  1 +//
  2 +// RootViewController.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 16/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "RootViewController.h"
  10 +#import "SynchronousViewController.h"
  11 +#import "QueueViewController.h"
  12 +#import "AuthenticationViewController.h"
  13 +#import "UploadViewController.h"
  14 +
  15 +@implementation RootViewController
  16 +
  17 +
  18 +- (void)viewDidLoad
  19 +{
  20 + [super viewDidLoad];
  21 + self.contentSizeForViewInPopover = CGSizeMake(310.0, self.tableView.rowHeight*4.0);
  22 +}
  23 +
  24 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  25 + return YES;
  26 +}
  27 +
  28 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  29 +{
  30 + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
  31 + if (!cell) {
  32 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
  33 + }
  34 + switch ([indexPath row]) {
  35 + case 0:
  36 + [[cell textLabel] setText:@"Synchronous"];
  37 + break;
  38 + case 1:
  39 + [[cell textLabel] setText:@"Queue"];
  40 + break;
  41 + case 2:
  42 + [[cell textLabel] setText:@"Authentication"];
  43 + break;
  44 + case 3:
  45 + [[cell textLabel] setText:@"Upload"];
  46 + break;
  47 + }
  48 + return cell;
  49 +}
  50 +
  51 +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  52 +{
  53 + return 4;
  54 +}
  55 +
  56 +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  57 +{
  58 + UIViewController *viewController = nil;
  59 + switch ([indexPath row]) {
  60 + case 0:
  61 + viewController = [[[SynchronousViewController alloc] initWithNibName:@"Sample" bundle:nil] autorelease];
  62 + break;
  63 + case 1:
  64 + viewController = [[[QueueViewController alloc] initWithNibName:@"Sample" bundle:nil] autorelease];
  65 + break;
  66 + case 2:
  67 + viewController = [[[AuthenticationViewController alloc] initWithNibName:@"Sample" bundle:nil] autorelease];
  68 + break;
  69 + case 3:
  70 + viewController = [[[UploadViewController alloc] initWithNibName:@"Sample" bundle:nil] autorelease];
  71 + break;
  72 + }
  73 + [splitViewController setViewControllers:[NSArray arrayWithObjects:[self navigationController],viewController,nil]];
  74 +
  75 + // Dismiss the popover if it's present.
  76 + if ([self popoverController]) {
  77 + [[self popoverController] dismissPopoverAnimated:YES];
  78 + }
  79 +
  80 + // Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
  81 + if ([self rootPopoverButtonItem]) {
  82 + [[[(id)viewController navigationBar] topItem] setLeftBarButtonItem:[self rootPopoverButtonItem] animated:NO];
  83 + }
  84 +
  85 +}
  86 +
  87 +- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc
  88 +{
  89 + [barButtonItem setTitle:@"More Examples"];
  90 + [self setPopoverController:pc];
  91 + [self setRootPopoverButtonItem:barButtonItem];
  92 + SampleViewController *detailViewController = [[splitViewController viewControllers] objectAtIndex:1];
  93 + [detailViewController showNavigationButton:barButtonItem];
  94 +}
  95 +
  96 +- (void)splitViewController:(UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
  97 +{
  98 + [self setPopoverController:nil];
  99 + [self setRootPopoverButtonItem:nil];
  100 + SampleViewController *detailViewController = [[splitViewController viewControllers] objectAtIndex:1];
  101 + [detailViewController hideNavigationButton:barButtonItem];
  102 +}
  103 +
  104 +- (void)splitViewController:(UISplitViewController *)svc popoverController: (UIPopoverController *)pc willPresentViewController: (UIViewController *)aViewController
  105 +{
  106 + if (pc != nil) {
  107 + [pc dismissPopoverAnimated:YES];
  108 + }
  109 +}
  110 +
  111 +
  112 +@synthesize splitViewController;
  113 +@synthesize popoverController;
  114 +@synthesize rootPopoverButtonItem;
  115 +@end
  1 +//
  2 +// SampleViewController.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +
  12 +@interface SampleViewController : UIViewController <UITableViewDelegate> {
  13 + UINavigationBar *navigationBar;
  14 + UITableView *tableView;
  15 +}
  16 +
  17 +- (void)showNavigationButton:(UIBarButtonItem *)button;
  18 +- (void)hideNavigationButton:(UIBarButtonItem *)button;
  19 +
  20 +@property (retain, nonatomic) IBOutlet UINavigationBar *navigationBar;
  21 +@property (retain, nonatomic) IBOutlet UITableView *tableView;
  22 +@end
  1 +//
  2 +// SampleViewController.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "SampleViewController.h"
  10 +
  11 +
  12 +@implementation SampleViewController
  13 +
  14 +- (void)showNavigationButton:(UIBarButtonItem *)button
  15 +{
  16 + [[[self navigationBar] topItem] setLeftBarButtonItem:button animated:NO];
  17 +}
  18 +
  19 +- (void)hideNavigationButton:(UIBarButtonItem *)button
  20 +{
  21 + [[[self navigationBar] topItem] setLeftBarButtonItem:nil animated:NO];
  22 +}
  23 +
  24 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  25 +{
  26 + return YES;
  27 +}
  28 +
  29 +- (NSIndexPath *)tableView:(UITableView *)theTableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  30 +{
  31 + return nil;
  32 +}
  33 +
  34 +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  35 +{
  36 + [[self tableView] reloadData];
  37 +}
  38 +
  39 +
  40 +- (void)viewDidUnload {
  41 + [super viewDidUnload];
  42 + [self setNavigationBar:nil];
  43 + [self setTableView:nil];
  44 +}
  45 +
  46 +
  47 +- (void)dealloc {
  48 + [navigationBar release];
  49 + [tableView release];
  50 + [super dealloc];
  51 +}
  52 +
  53 +@synthesize navigationBar;
  54 +@synthesize tableView;
  55 +@end
1 // 1 //
2 // SynchronousViewController.h 2 // SynchronousViewController.h
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
  10 +#import "SampleViewController.h"
  11 +@class ASIHTTPRequest;
10 12
  13 +@interface SynchronousViewController : SampleViewController {
  14 + ASIHTTPRequest *request;
  15 + UITextField *urlField;
  16 + UITextView *responseField;
11 17
12 -@interface SynchronousViewController : UIViewController {  
13 - IBOutlet UITextView *htmlSource;  
14 } 18 }
15 - (IBAction)simpleURLFetch:(id)sender; 19 - (IBAction)simpleURLFetch:(id)sender;
16 20
  21 +@property (retain, nonatomic) ASIHTTPRequest *request;
  22 +
17 @end 23 @end
1 // 1 //
2 // SynchronousViewController.m 2 // SynchronousViewController.m
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
@@ -8,23 +8,183 @@ @@ -8,23 +8,183 @@
8 8
9 #import "SynchronousViewController.h" 9 #import "SynchronousViewController.h"
10 #import "ASIHTTPRequest.h" 10 #import "ASIHTTPRequest.h"
  11 +#import "DetailCell.h"
  12 +#import "InfoCell.h"
11 13
12 @implementation SynchronousViewController 14 @implementation SynchronousViewController
13 15
  16 +
  17 +// Runs a request synchronously
14 - (IBAction)simpleURLFetch:(id)sender 18 - (IBAction)simpleURLFetch:(id)sender
15 { 19 {
16 - ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/"]] autorelease]; 20 +
  21 + NSURL *url = [NSURL URLWithString:[urlField text]];
  22 + // Create a request
  23 + // You don't normally need to retain a synchronous request, but we need to in this case because we'll need it later if we reload the table data
  24 + [self setRequest:[ASIHTTPRequest requestWithURL:url]];
17 25
18 //Customise our user agent, for no real reason 26 //Customise our user agent, for no real reason
19 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 27 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
20 28
  29 + // Start the request
21 [request startSynchronous]; 30 [request startSynchronous];
22 - if ([request error]) { 31 +
23 - [htmlSource setText:[[request error] localizedDescription]]; 32 + // Request has now finished
24 - } else if ([request responseString]) { 33 + [[self tableView] reloadData];
25 - [htmlSource setText:[request responseString]]; 34 +
  35 +}
  36 +
  37 +/*
  38 +Most of the code below here relates to the table view, and isn't that interesting
  39 +*/
  40 +
  41 +- (void)viewDidLoad
  42 +{
  43 + [[[self navigationBar] topItem] setTitle:@"Synchronous Requests"];
  44 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  45 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  46 +
  47 +}
  48 +
  49 +
  50 +- (void)dealloc
  51 +{
  52 + [request cancel];
  53 + [request release];
  54 + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  55 + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  56 + [super dealloc];
  57 +}
  58 +
  59 +- (void)keyboardWillShow:(NSNotification *)notification
  60 +{
  61 + NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
  62 + CGRect keyboardBounds;
  63 + [keyboardBoundsValue getValue:&keyboardBounds];
  64 + UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height-42, 0);
  65 + [[self tableView] setScrollIndicatorInsets:e];
  66 + [[self tableView] setContentInset:e];
  67 +}
  68 +
  69 +- (void)keyboardWillHide:(NSNotification *)notification
  70 +{
  71 + UIEdgeInsets e = UIEdgeInsetsMake(0, 0, 0, 0);
  72 + [[self tableView] setScrollIndicatorInsets:e];
  73 + [[self tableView] setContentInset:e];
  74 +}
  75 +
  76 +static NSString *intro = @"Demonstrates fetching a web page synchronously, the HTML source will appear in the box below when the download is complete. The interface will lock up when you press this button until the operation times out or succeeds. You should avoid using synchronous requests on the main thread, even for the simplest operations.";
  77 +
  78 +- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  79 +{
  80 + UITableViewCell *cell;
  81 + if ([indexPath section] == 0) {
  82 + cell = [InfoCell cellWithDescription:intro];
  83 + } else if ([indexPath section] == 3) {
  84 + cell = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];
  85 + if (!cell) {
  86 + cell = [DetailCell cell];
  87 + }
  88 + } else {
  89 + cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
  90 + if (!cell) {
  91 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
  92 + }
26 } 93 }
  94 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  95 + NSString *key;
  96 +
  97 + int tablePadding = 40;
  98 + int tableWidth = [tableView frame].size.width;
  99 + if (tableWidth > 480) { // iPad
  100 + tablePadding = 110;
  101 + }
  102 +
  103 + switch ([indexPath section]) {
  104 + case 1:
  105 + urlField = [[[UITextField alloc] initWithFrame:CGRectMake(10,12,tableWidth-tablePadding-40,20)] autorelease];
  106 + if ([self request]) {
  107 + [urlField setText:[[[self request] url] absoluteString]];
  108 + } else {
  109 + [urlField setText:@"http://allseeing-i.com"];
  110 + }
  111 + UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  112 + [goButton setFrame:CGRectMake(tableWidth-tablePadding-38,7,20,20)];
  113 + [goButton setTitle:@"Go!" forState:UIControlStateNormal];
  114 + [goButton sizeToFit];
  115 + [goButton addTarget:self action:@selector(simpleURLFetch:) forControlEvents:UIControlEventTouchUpInside];
  116 + [[cell contentView] addSubview:goButton];
  117 + [[cell contentView] addSubview:urlField];
  118 + break;
  119 + case 2:
  120 +
  121 + responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease];
  122 + [responseField setBackgroundColor:[UIColor clearColor]];
  123 + [[cell contentView] addSubview:responseField];
  124 + if (request) {
  125 + if ([request error]) {
  126 + [responseField setText:[[request error] localizedDescription]];
  127 + } else if ([request responseString]) {
  128 + [responseField setText:[request responseString]];
  129 + }
  130 + }
  131 + break;
  132 + case 3:
  133 + key = [[[request responseHeaders] allKeys] objectAtIndex:[indexPath row]];
  134 + [[cell textLabel] setText:key];
  135 + [[cell detailTextLabel] setText:[[request responseHeaders] objectForKey:key]];
  136 + break;
  137 + }
  138 + return cell;
  139 +}
  140 +
  141 +- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
  142 +{
  143 + if (section == 3) {
  144 + return [[request responseHeaders] count];
  145 + } else {
  146 + return 1;
  147 + }
  148 +}
  149 +
  150 +- (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  151 +{
  152 + if ([indexPath section] == 0) {
  153 + return [InfoCell neededHeightForDescription:intro withTableWidth:[tableView frame].size.width]+20;
  154 + } else if ([indexPath section] == 1) {
  155 + return 48;
  156 + } else if ([indexPath section] == 2) {
  157 + return 160;
  158 + } else {
  159 + return 34;
  160 + }
  161 +}
  162 +
  163 +- (NSString *)tableView:(UITableView *)theTableView titleForHeaderInSection:(NSInteger)section
  164 +{
  165 + switch (section) {
  166 + case 0:
  167 + return nil;
  168 + case 1:
  169 + return @"Enter a URL";
  170 + case 2:
  171 + return @"Response";
  172 + case 3:
  173 + return @"Response Headers";
  174 + }
  175 + return nil;
27 } 176 }
28 177
  178 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  179 +{
  180 + if ([self request]) {
  181 + return 4;
  182 + } else {
  183 + return 2;
  184 + }
  185 +}
  186 +
  187 +
  188 +@synthesize request;
29 189
30 @end 190 @end
  1 +//
  2 +// ToggleCell.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +
  12 +@interface ToggleCell : UITableViewCell {
  13 + UISwitch *toggle;
  14 +}
  15 ++ (id)cell;
  16 +
  17 +@property (assign, nonatomic) UISwitch *toggle;
  18 +@end
  1 +//
  2 +// ToggleCell.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 17/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "ToggleCell.h"
  10 +
  11 +
  12 +@implementation ToggleCell
  13 +
  14 ++ (id)cell
  15 +{
  16 + ToggleCell *cell = [[[ToggleCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ToggleCell"] autorelease];
  17 + [[cell textLabel] setTextAlignment:UITextAlignmentLeft];
  18 + [cell setToggle:[[[UISwitch alloc] initWithFrame:CGRectMake(0,0,20,20)] autorelease]];
  19 + [cell setAccessoryView:[cell toggle]];
  20 + return cell;
  21 +}
  22 +
  23 +@synthesize toggle;
  24 +@end
1 // 1 //
2 // UploadViewController.h 2 // UploadViewController.h
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 31/12/2008. 5 // Created by Ben Copsey on 31/12/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
  10 +#import "SampleViewController.h"
  11 +@class ASIFormDataRequest;
10 12
11 -@class ASINetworkQueue; 13 +@interface UploadViewController : SampleViewController {
12 - 14 +
13 -@interface UploadViewController : UIViewController { 15 + ASIFormDataRequest *request;
14 - ASINetworkQueue *networkQueue; 16 +
15 IBOutlet UIProgressView *progressIndicator; 17 IBOutlet UIProgressView *progressIndicator;
  18 + UITextView *resultView;
16 } 19 }
17 20
18 - (IBAction)performLargeUpload:(id)sender; 21 - (IBAction)performLargeUpload:(id)sender;
19 - (IBAction)toggleThrottling:(id)sender; 22 - (IBAction)toggleThrottling:(id)sender;
  23 +
  24 +@property (retain, nonatomic) ASIFormDataRequest *request;
20 @end 25 @end
1 // 1 //
2 // UploadViewController.m 2 // UploadViewController.m
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 31/12/2008. 5 // Created by Ben Copsey on 31/12/2008.
6 // Copyright 2008 All-Seeing Interactive. All rights reserved. 6 // Copyright 2008 All-Seeing Interactive. All rights reserved.
@@ -8,28 +8,22 @@ @@ -8,28 +8,22 @@
8 8
9 #import "UploadViewController.h" 9 #import "UploadViewController.h"
10 #import "ASIFormDataRequest.h" 10 #import "ASIFormDataRequest.h"
11 -#import "ASINetworkQueue.h" 11 +#import "InfoCell.h"
12 12
13 @implementation UploadViewController 13 @implementation UploadViewController
14 14
15 -  
16 -- (void)awakeFromNib  
17 -{  
18 - networkQueue = [[ASINetworkQueue alloc] init];  
19 -}  
20 -  
21 - (IBAction)performLargeUpload:(id)sender 15 - (IBAction)performLargeUpload:(id)sender
22 { 16 {
23 - [networkQueue cancelAllOperations]; 17 + [request cancel];
24 - [networkQueue setShowAccurateProgress:YES]; 18 + [self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ignore"]]];
25 - [networkQueue setUploadProgressDelegate:progressIndicator];  
26 - [networkQueue setDelegate:self];  
27 -  
28 - ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ignore"]] autorelease];  
29 [request setPostValue:@"test" forKey:@"value1"]; 19 [request setPostValue:@"test" forKey:@"value1"];
30 [request setPostValue:@"test" forKey:@"value2"]; 20 [request setPostValue:@"test" forKey:@"value2"];
31 [request setPostValue:@"test" forKey:@"value3"]; 21 [request setPostValue:@"test" forKey:@"value3"];
32 [request setTimeOutSeconds:20]; 22 [request setTimeOutSeconds:20];
  23 + [request setUploadProgressDelegate:progressIndicator];
  24 + [request setDelegate:self];
  25 + [request setDidFailSelector:@selector(uploadFailed:)];
  26 + [request setDidFinishSelector:@selector(uploadFinished:)];
33 27
34 //Create a 256KB file 28 //Create a 256KB file
35 NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease]; 29 NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease];
@@ -42,8 +36,8 @@ @@ -42,8 +36,8 @@
42 [request setFile:path forKey:[NSString stringWithFormat:@"file-%hi",i]]; 36 [request setFile:path forKey:[NSString stringWithFormat:@"file-%hi",i]];
43 } 37 }
44 38
45 - [networkQueue addOperation:request]; 39 + [request startAsynchronous];
46 - [networkQueue go]; 40 + [resultView setText:@"Uploading data..."];
47 } 41 }
48 42
49 - (IBAction)toggleThrottling:(id)sender 43 - (IBAction)toggleThrottling:(id)sender
@@ -51,9 +45,122 @@ @@ -51,9 +45,122 @@
51 [ASIHTTPRequest setShouldThrottleBandwidthForWWAN:[(UISwitch *)sender isOn]]; 45 [ASIHTTPRequest setShouldThrottleBandwidthForWWAN:[(UISwitch *)sender isOn]];
52 } 46 }
53 47
54 -- (void)dealloc { 48 +- (void)uploadFailed:(ASIHTTPRequest *)theRequest
55 - [networkQueue release]; 49 +{
  50 + [resultView setText:[NSString stringWithFormat:@"Request failed:\r\n%@",[[theRequest error] localizedDescription]]];
  51 +}
  52 +
  53 +- (void)uploadFinished:(ASIHTTPRequest *)theRequest
  54 +{
  55 + [resultView setText:[NSString stringWithFormat:@"Finished uploading %llu bytes of data",[theRequest postLength]]];
  56 +}
  57 +
  58 +- (void)dealloc
  59 +{
  60 + [request cancel];
  61 + [request release];
56 [super dealloc]; 62 [super dealloc];
57 } 63 }
58 64
  65 +/*
  66 + Most of the code below here relates to the table view, and isn't that interesting
  67 + */
  68 +
  69 +- (void)viewDidLoad
  70 +{
  71 + [[[self navigationBar] topItem] setTitle:@"Tracking Upload Progress"];
  72 +}
  73 +
  74 +static NSString *intro = @"Demonstrates POSTing content to a URL, showing upload progress.\nYou'll only see accurate progress for uploads when the request body is larger than 128KB (in 2.2.1 SDK), or when the request body is larger than 32KB (in 3.0 SDK)";
  75 +
  76 +- (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInteger)section
  77 +{
  78 + if (section == 1) {
  79 + int tablePadding = 40;
  80 + int tableWidth = [tableView frame].size.width;
  81 + if (tableWidth > 480) { // iPad
  82 + tablePadding = 110;
  83 + }
  84 +
  85 + UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0,0,tableWidth-(tablePadding/2),30)] autorelease];
  86 + UIButton *goButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  87 + [goButton setTitle:@"Go!" forState:UIControlStateNormal];
  88 + [goButton sizeToFit];
  89 + [goButton setFrame:CGRectMake([view frame].size.width-[goButton frame].size.width+10,7,[goButton frame].size.width,[goButton frame].size.height)];
  90 +
  91 + [goButton addTarget:self action:@selector(performLargeUpload:) forControlEvents:UIControlEventTouchUpInside];
  92 + [view addSubview:goButton];
  93 +
  94 + progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease];
  95 + [view addSubview:progressIndicator];
  96 +
  97 + return view;
  98 + }
  99 + return nil;
  100 +}
  101 +
  102 +- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  103 +{
  104 + UITableViewCell *cell;
  105 + if ([indexPath section] == 0) {
  106 + cell = [InfoCell cellWithDescription:intro];
  107 + } else {
  108 + cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
  109 + if (!cell) {
  110 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
  111 + }
  112 + }
  113 + [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  114 +
  115 + int tablePadding = 40;
  116 + int tableWidth = [tableView frame].size.width;
  117 + if (tableWidth > 480) { // iPad
  118 + tablePadding = 110;
  119 + }
  120 +
  121 + switch ([indexPath section]) {
  122 +
  123 + case 2:
  124 +
  125 + resultView = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,60)] autorelease];
  126 + [resultView setBackgroundColor:[UIColor clearColor]];
  127 + [[cell contentView] addSubview:resultView];
  128 + break;
  129 + }
  130 + return cell;
  131 +}
  132 +
  133 +- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section
  134 +{
  135 + if (section == 1) {
  136 + return 0;
  137 + }
  138 + return 1;
  139 +}
  140 +
  141 +- (CGFloat)tableView:(UITableView *)theTableView heightForHeaderInSection:(NSInteger)section
  142 +{
  143 + if (section == 1) {
  144 + return 50;
  145 + }
  146 + return 34;
  147 +}
  148 +
  149 +- (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  150 +{
  151 + if ([indexPath section] == 0) {
  152 + return [InfoCell neededHeightForDescription:intro withTableWidth:[tableView frame].size.width]+20;
  153 + } else if ([indexPath section] == 2) {
  154 + return 80;
  155 + } else {
  156 + return 42;
  157 + }
  158 +}
  159 +
  160 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  161 +{
  162 + return 3;
  163 +}
  164 +
  165 +@synthesize request;
59 @end 166 @end
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
@@ -4,12 +4,14 @@ @@ -4,12 +4,14 @@
4 <dict> 4 <dict>
5 <key>CFBundleDevelopmentRegion</key> 5 <key>CFBundleDevelopmentRegion</key>
6 <string>English</string> 6 <string>English</string>
  7 + <key>CFBundleDisplayName</key>
  8 + <string>ASIHTTPRequest Demo</string>
7 <key>CFBundleExecutable</key> 9 <key>CFBundleExecutable</key>
8 <string>${EXECUTABLE_NAME}</string> 10 <string>${EXECUTABLE_NAME}</string>
9 <key>CFBundleIconFile</key> 11 <key>CFBundleIconFile</key>
10 <string>iphone-icon.png</string> 12 <string>iphone-icon.png</string>
11 <key>CFBundleIdentifier</key> 13 <key>CFBundleIdentifier</key>
12 - <string>com.allseeinginteractive.asihttprequest.sample</string> 14 + <string>com.allseeinginteractive.asihttprequest.ipad.sample</string>
13 <key>CFBundleInfoDictionaryVersion</key> 15 <key>CFBundleInfoDictionaryVersion</key>
14 <string>6.0</string> 16 <string>6.0</string>
15 <key>CFBundlePackageType</key> 17 <key>CFBundlePackageType</key>
@@ -19,8 +21,6 @@ @@ -19,8 +21,6 @@
19 <key>CFBundleVersion</key> 21 <key>CFBundleVersion</key>
20 <string>1.0</string> 22 <string>1.0</string>
21 <key>NSMainNibFile</key> 23 <key>NSMainNibFile</key>
22 - <string>MainWindow</string> 24 + <string>iPadMainWindow</string>
23 - <key>CFBundleDisplayName</key>  
24 - <string>ASIHTTPRequest Demo</string>  
25 </dict> 25 </dict>
26 </plist> 26 </plist>
  1 +//
  2 +// iPadSampleAppDelegate.h
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 15/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface iPadSampleAppDelegate : NSObject <UIApplicationDelegate> {
  12 + UIWindow *window;
  13 + UISplitViewController *splitViewController;
  14 +}
  15 +
  16 +@property (nonatomic, retain) IBOutlet UIWindow *window;
  17 +@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
  18 +
  19 +@end
  1 +//
  2 +// iPadSampleAppDelegate.m
  3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
  4 +//
  5 +// Created by Ben Copsey on 15/06/2010.
  6 +// Copyright 2010 All-Seeing Interactive. All rights reserved.
  7 +//
  8 +
  9 +#import "iPadSampleAppDelegate.h"
  10 +
  11 +@implementation iPadSampleAppDelegate
  12 +
  13 +- (void)applicationDidFinishLaunching:(UIApplication *)application
  14 +{
  15 + [window addSubview:[splitViewController view]];
  16 + [window makeKeyAndVisible];
  17 +}
  18 +
  19 +- (void)dealloc {
  20 + [splitViewController release];
  21 + [window release];
  22 + [super dealloc];
  23 +}
  24 +
  25 +
  26 +@synthesize window;
  27 +@synthesize splitViewController;
  28 +@end
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>CFBundleDevelopmentRegion</key>
  6 + <string>English</string>
  7 + <key>CFBundleDisplayName</key>
  8 + <string>ASIHTTPRequest Demo</string>
  9 + <key>CFBundleExecutable</key>
  10 + <string>${EXECUTABLE_NAME}</string>
  11 + <key>CFBundleIconFile</key>
  12 + <string>iphone-icon.png</string>
  13 + <key>CFBundleIdentifier</key>
  14 + <string>com.allseeinginteractive.asihttprequest.iphone.sample</string>
  15 + <key>CFBundleInfoDictionaryVersion</key>
  16 + <string>6.0</string>
  17 + <key>CFBundlePackageType</key>
  18 + <string>APPL</string>
  19 + <key>CFBundleSignature</key>
  20 + <string>????</string>
  21 + <key>CFBundleVersion</key>
  22 + <string>1.0</string>
  23 + <key>NSMainNibFile</key>
  24 + <string>iPhoneMainWindow</string>
  25 +</dict>
  26 +</plist>
1 // 1 //
2 // iPhoneSampleAppDelegate.h 2 // iPhoneSampleAppDelegate.h
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright All-Seeing Interactive 2008. All rights reserved. 6 // Copyright All-Seeing Interactive 2008. All rights reserved.
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 15
16 } 16 }
17 17
18 -  
19 @property (nonatomic, retain) IBOutlet UIWindow *window; 18 @property (nonatomic, retain) IBOutlet UIWindow *window;
20 @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; 19 @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
21 20
1 // 1 //
2 // iPhoneSampleAppDelegate.m 2 // iPhoneSampleAppDelegate.m
3 -// asi-http-request 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 07/11/2008. 5 // Created by Ben Copsey on 07/11/2008.
6 // Copyright All-Seeing Interactive 2008. All rights reserved. 6 // Copyright All-Seeing Interactive 2008. All rights reserved.
@@ -12,12 +12,8 @@ @@ -12,12 +12,8 @@
12 12
13 @implementation iPhoneSampleAppDelegate 13 @implementation iPhoneSampleAppDelegate
14 14
15 -@synthesize window; 15 +- (void)dealloc
16 -@synthesize tabBarController; 16 +{
17 -  
18 -  
19 -  
20 -- (void)dealloc {  
21 [tabBarController release]; 17 [tabBarController release];
22 [window release]; 18 [window release];
23 [super dealloc]; 19 [super dealloc];
@@ -26,7 +22,7 @@ @@ -26,7 +22,7 @@
26 - (void)applicationDidFinishLaunching:(UIApplication *)application { 22 - (void)applicationDidFinishLaunching:(UIApplication *)application {
27 // Add the tab bar controller's current view as a subview of the window 23 // Add the tab bar controller's current view as a subview of the window
28 [window addSubview:[tabBarController view]]; 24 [window addSubview:[tabBarController view]];
29 - [[tabBarController view] setFrame:CGRectMake(0,47,320,433)]; 25 + [[tabBarController view] setFrame:CGRectMake(0,42,320,438)];
30 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateStatus:) userInfo:nil repeats:YES]; 26 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateStatus:) userInfo:nil repeats:YES];
31 } 27 }
32 28
@@ -47,5 +43,8 @@ @@ -47,5 +43,8 @@
47 } 43 }
48 44
49 45
  46 +@synthesize window;
  47 +@synthesize tabBarController;
  48 +
50 @end 49 @end
51 50
1 // 1 //
2 // main.m 2 // main.m
3 -// iPhone 3 +// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
4 // 4 //
5 // Created by Ben Copsey on 22/03/2009. 5 // Created by Ben Copsey on 22/03/2009.
6 // Copyright All-Seeing Interactive 2009. All rights reserved. 6 // Copyright All-Seeing Interactive 2009. All rights reserved.
This diff was suppressed by a .gitattributes entry.