I'm trying to get Google search autocomplete working in my app, but I've run into some trouble. I'm using a UISearchBar
and it's textDidChange
delegate method to do so. When the text changes, I use NSXmlParser
to read an XML file like this one:
<toplevel>
<CompleteSuggestion>
<suggestion data="searchterms"/>
<num_queries int="13400000"/>
</CompleteSuggestion>
<CompleteSuggestion>
<suggestion data="searchterms twitter"/>
<num_queries int="52500000"/>
</CompleteSuggestion>
</toplevel>
http://suggestqueries.google.com/complete/search?client=toolbar&q=SEARCHTERM
Where SEARCHTERM would be the UISearchBar text. This returns an XML file, which I would then parse to find the suggested term using
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
but I'm not quite sure how to.