iOS7 & RESTKit 0.20.3
Below is the URL that I need to hit to get a response from Google Maps APIs (I changed the key):
When I type the URL above in the browser, I get a JSON back (200 OK)
input
is the search string the user provides. I have hard-coded it into the URL above.
The following is what I have tried and get a 404 error:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/placeautocomplete/json?input=%@&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000", [input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
method:RKRequestMethodGET
pathPattern:@""
keyPath:@"predictions" statusCodes:statusCodeSet];
I have also tried the following that gives an error Code=1001 "No response descriptors match the response loaded."
:
NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKMapping *mapping = [TBSRESTMappingProvider googleAutoCompleteMapping];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=coffee&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
method:RKRequestMethodGET
pathPattern:@""
keyPath:@"predictions" statusCodes:statusCodeSet];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request
responseDescriptors:@[responseDescriptor]];
input
sensor
location
key
and radius
?Code=1001 "No response descriptors match the response loaded."
?The URL path that you request needs to match against the path pattern you supply to the response descriptor. If you want to work the way you are then set the path pattern to nil
(which matches everything).
Best practice would generally be to use an RKObjectManager
instance and call getObjectsAtPath:parameters:success:failure:
and passing a dictionary of parameters that should be appended to the request URL (built from the base URL, path and parameters).