I need to implement a simultaneous search in two search engines. I have two functions:
*- (void) searchYoutube: (NSString )text and
*- (void) searchYahoo:(NSString )text
(void) searchYahoo:(NSString *)text{
NSString *urlString = [NSString stringWithFormat:@"http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=%@&output=json&query=%@&results=30", YahooAppId, text];
NSLog(@"URL zaprosa: %@",urlString);
//Create NSURL string from formatted string
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *connection = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
if (connection)
{
NSLog(@"Data will be received from URL: %@", url);
}
else
{
NSLog(@"Data couldn't be received from URL: %@", url);
}}
Function -searchYoutube: is similar to the above. But when I call query with these two functions, I see
2011-06-26 14:06:27.523 TrueSearcher[5373:207] URL query: http://gdata.youtube.com/feeds/api/videos?q=os&start-index=1&max-results=30&alt=jsonc&v=2
2011-06-26 14:06:27.874 TrueSearcher[5373:207] Data will be received from URL: http://gdata.youtube.com/feeds/api/videos?q=os&start-index=1&max-results=30&alt=jsonc&v=2
2011-06-26 14:06:27.875 TrueSearcher[5373:207] URL query: http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=jwGJkT32&output=json&query=os&results=30
2011-06-26 14:06:29.010 TrueSearcher[5373:207] Data will be received from URL: http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=jwGJkT32&output=json&query=os&results=30
And that’s all. I can’t receive any data. What am I doing wrong?
Well,
Is wrong.
sendSynchronousRequestreturns an(NSData *)with the response data. So, a more correct way to do what you want isAnd then you read the response from
responseData.You should also take a look at the documentation for NSURLConnection.