using iphone's nsurlconnection class

8

Click here to load reader

Upload: leon-ho

Post on 07-May-2015

20.246 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Using iPhone's NSURLConnection class

Web Services Connection

Page 2: Using iPhone's NSURLConnection class

#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

#2

[NSThread detachNewThreadSelector: @selector(getJSON) toTarget:self withObject:nil];

Page 4: Using iPhone's NSURLConnection class

#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

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

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

My Approach