1

Hello I am developing one application as currency converter in that, I have URL it will return only one country currency but my module look like if user select one country then I need to display list of currency converter values of more than one country so I need call josn more than one times.
code is as:

    responseData = [[NSMutableData data] retain];
    ArrData = [NSMutableArray array];
    NSString *strURL = [NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=1",strtablbase,strto];
    NSURL *url = [NSURL URLWithString:strURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; [responseData release];

results = [responseString JSONValue];
livevalues=[responseString JSONValue];

With above code I am geting one country values but I need pass one strto values differently Is it possible? If yes, please give suggestions & help me out from this problem.

areddy
  • 77
  • 2
  • 14
  • Please upvote the answers which have helped you to solve your problem, instead of writing thank you as comment. If you think one of them is correct then check it as answer. – Mert Feb 28 '13 at 08:32

3 Answers3

0

Yes you can use NSOperation Queues to call the different URL or if you are using Asihttprequest this Link may be useful for you :)

Community
  • 1
  • 1
DAMM108
  • 970
  • 2
  • 13
  • 27
  • first of all thanks for suggestion...can pls give me some idea about how can use that link ? – areddy Feb 27 '13 at 09:18
  • The link refers to an answer for requests which is made with ASIHttpRequest Framework which can be found here http://allseeing-i.com/ASIHTTPRequest. But the framework is old and the developer does not work on it, he says it on the homepage. He does not recommend to use this framework anymore. – Mert Feb 27 '13 at 09:35
0

Of course it is possible to pass different values. Like you already did you can start connections one after another. If the server belongs to you, I would implement a request which returns me all the rates at a time. It saves the time for sending and receiving request. It really does not matter (for waiting time) if you get 100 bytes or 500 bytes in one request.

Otherwise you need to call many requests. Like said you can call one after another and even 2-3 requests at the same time. You can implement the mechanism your self or you can use NSOperationQueue which is made exactly for many requests by Apple.

For more information https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html

And I want yo point the method (of NSURLConnection)

+ (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))handler
Mert
  • 6,025
  • 3
  • 21
  • 33
0
responseData = [[NSMutableData data] retain];

NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:@"country1"];
    [array addObject:@"country2"];

    for (NSString *urlString in array) {
strtablbase = [NSString stringWithFormat:@"%@",urlString];
    NSString *strURL = [NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=1",strtablbase,strto];
    NSURL *url = [NSURL URLWithString:strURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

Try this..

Rahul
  • 134
  • 6