Using iPhone's NSURLConnection class
Click here to load reader
-
Upload
leon-ho -
Category
Technology
-
view
20.246 -
download
1
Transcript of Using iPhone's NSURLConnection class
![Page 1: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/1.jpg)
Web Services Connection
![Page 2: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/2.jpg)
#1
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/geo?output=json&q=
%@” address, nil]];
NSString *data = [[NSString alloc] initWithContentsOfURL:url];
![Page 3: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/3.jpg)
#2
[NSThread detachNewThreadSelector: @selector(getJSON) toTarget:self withObject:nil];
![Page 4: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/4.jpg)
#3
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: @”http://www.google.com” ]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [connection release];[request release];
![Page 5: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/5.jpg)
NSURLConnection
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
![Page 6: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/6.jpg)
Problem
• Every initialized NSURLConnection shares the same delegate methods, unless you delegate to different objects.
• You could implement a class for holding all those these, but you need to create a object of that class for every download. Not good.
![Page 7: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/7.jpg)
My Approach
![Page 8: Using iPhone's NSURLConnection class](https://reader037.fdocuments.in/reader037/viewer/2022100323/554a48f3b4c90582328b57e8/html5/thumbnails/8.jpg)
http://github.com/leonho/iphone-libs