English 中文(简体)
两条国家措施
原标题:Managing two NSURLConnection

I want to do two async request from two different kml file, so I setup two requests first:

NSString *server1URL = [NSString stringWithFormat:...];
NSMutableURLRequest *firstRequest =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:server1URL]];
[firstRequest setHTTPMethod:@"GET"];
NSURLConnection *AConnection = [NSURLConnection connectionWithRequest:firstRequest delegate:self];

NSString *server2URL = [NSString stringWithFormat:...];
NSMutableURLRequest *secondRequest =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:server2URL]];
[secondRequest setHTTPMethod:@"GET"];
NSURLConnection *BConnection = [NSURLConnection connectionWithRequest:secondRequest delegate:self];

Then I init NSMutableData I will be using:

AResponseData = [[NSMutableData alloc] init];
BResponseData = [[NSMutableData alloc] init];

然后,请见。 担任这一职务:

connectionToInfoMapping = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue(connectionToInfoMapping, AConnection, [NSMutableDictionary dictionaryWithObject:AResponseData forKey:@"receivedData"]);
CFDictionaryAddValue(connectionToInfoMapping, BConnection, [NSMutableDictionary dictionaryWithObject:BResponseData forKey:@"receivedData"]);

OK, then there re delegates:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    const NSMutableDictionary *connectionInfo = CFDictionaryGetValue(connectionToInfoMapping, connection);
    [[connectionInfo objectForKey:@"receivedData"] appendData:data];
}

因此,我可以获得与这一联系相匹配的正确的NSMutableData的数据。

Now in - (void)connectionDidFinishLoading:(NSURLConnection *)connection, I want to "If A finish, do this, if B finish, do this", and my question is, how can I do this?

最佳回答
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    if( [connection isEqual: AConnection] ){
        // do connection A stuff
    }
    else if( [connection isEqual: BConnection] ){
        // do connection B stuff
    }  
}
问题回答

利用德国航天中心发出同步请求:申请将在背景中处理。

Example:

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(queue, ^{
    NSURLRequest *request = [NSURLRequest requestWithURL:url1];
    NSURLResponse *response;
    NSError *error;
    NSData *data1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    // do something with the data
});

dispatch_async(queue, ^{
    NSURLRequest *request = [NSURLRequest requestWithURL:url2];
    NSURLResponse *response;
    NSError *error;
    NSData *data2 = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    // do something with the data
});

如何向每一条连接点分配标签,并通过连接中的一、一、二、二、二、二、二、三、三、三、三、三、三、三、三、三、三、三、三、三、三、三、三、三、四、三、三、三、三、四、三、三、四、三、三、三、四、三、三、四、三、三、三、四、四、三、三、三、三、三、四、一、一、一、一、二、二、二、三、一、二、一、一、一、一、一、二、一、一、一、一、二、二、二、二、二、二、二、二、一、一、二、二、一、一、一、一、二、二、二、二、二、二、二、二、二、二、二、二、二、二、一、二、一、一、二、一、一、二、二、一、一、二、一、一、一、一、二、二、一、一、二 难道吗?





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签