Jamie Pinkham

added use cases in iphone sample

... ... @@ -19,6 +19,12 @@
[self setRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/top_secret/"]]];
[request setUseKeychainPersistence:[useKeychain isOn]];
[request setDelegate:self];
[request setAuthenticationNeededBlock:^(ASIHTTPRequest *request){
NSLog(@"authentication needed");
}];
[request setProxyAuthenticationNeededBlock:^(ASIHTTPRequest *request){
NSLog(@"proxy authentication needed");
}];
[request setShouldPresentAuthenticationDialog:[useBuiltInDialog isOn]];
[request setDidFinishSelector:@selector(topSecretFetchComplete:)];
[request setDidFailSelector:@selector(topSecretFetchFailed:)];
... ...
... ... @@ -17,6 +17,16 @@
- (IBAction)fetchThreeImages:(id)sender
{
ASIHTTPRequestSizeBlock sizeBlock = ^(ASIHTTPRequest *request, long long size){
NSDictionary *userInfo = [request userInfo];
NSLog(@"request - %@ named = %@ download size incremented %lld", request, [userInfo valueForKey:@"name"], size);
};
ASIHTTPRequestProgressBlock bytesBlock = ^(ASIHTTPRequest *request, unsigned long long size, unsigned long long total){
NSDictionary *userInfo = [request userInfo];
NSLog(@"request - %@ named - %@ downloaded bytes size %llu of total: %llu", request, [userInfo valueForKey:@"name"], size, total);
};
[imageView1 setImage:nil];
[imageView2 setImage:nil];
[imageView3 setImage:nil];
... ... @@ -34,18 +44,27 @@
ASIHTTPRequest *request;
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
[request setDownloadSizeIncrementedBlock:sizeBlock];
[request setBytesReceivedBlock:bytesBlock];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator1];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
[networkQueue addOperation:request];
request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]] autorelease];
[request setDownloadSizeIncrementedBlock:sizeBlock];
[request setBytesReceivedBlock:bytesBlock];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator2];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request2" forKey:@"name"]];
[networkQueue addOperation:request];
request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]] autorelease];
[request setDownloadSizeIncrementedBlock:sizeBlock];
[request setBytesReceivedBlock:bytesBlock];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator3];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request3" forKey:@"name"]];
[networkQueue addOperation:request];
[networkQueue go];
... ...
... ... @@ -19,12 +19,41 @@
{
NSURL *url = [NSURL URLWithString:[urlField text]];
NSMutableData *recievedData = [NSMutableData data];
// Create a request
// 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
[self setRequest:[ASIHTTPRequest requestWithURL:url]];
//Customise our user agent, for no real reason
[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
[request setStartedBlock:^(ASIHTTPRequest *aRequest){
NSLog(@"started!");
}];
[request setHeadersReceivedBlock:^(ASIHTTPRequest *aRequest){
NSLog(@"headers recieved");
}];
[request setBytesReceivedBlock:^(ASIHTTPRequest *aRequest, unsigned long long length, unsigned long long total){
NSLog(@"bytes received:%llu of total: %llu", length, total);
}];
[request setDownloadSizeIncrementedBlock:^(ASIHTTPRequest *aRequest, long long length){
NSLog(@"download size incremented:%lld", length);
}];
[request setDataReceivedBlock:^(ASIHTTPRequest *aRequest, NSData *data){
[recievedData appendData:data];
NSLog(@"data - %@", recievedData);
}];
[request setCompletionBlock:^(ASIHTTPRequest *aRequest){
if ([aRequest error]) {
NSLog(@"error from block");
} else if ([aRequest responseString]) {
NSLog(@"finish from block");
}
}];
// Start the request
[request startSynchronous];
... ...
... ... @@ -20,10 +20,17 @@
[request setPostValue:@"test" forKey:@"value2"];
[request setPostValue:@"test" forKey:@"value3"];
[request setTimeOutSeconds:20];
[request setUploadProgressDelegate:progressIndicator];
[request setBytesSentBlock:^(ASIHTTPRequest *request, unsigned long long length, unsigned long long total){
NSLog(@"sent %llu bytes of %llu total", length, total);
}];
[request setUploadSizeIncrementedBlock:^(ASIHTTPRequest *request, long long length){
NSLog(@"upload size incremented = %lld",length);
}];
/*[request setUploadProgressDelegate:progressIndicator];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request setDidFinishSelector:@selector(uploadFinished:)];*/
//Create a 256KB file
NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease];
... ...