【发布时间】:2014-03-22 14:57:23
【问题描述】:
iOS7 和 RESTKit 0.20.3
以下是我需要点击以从 Google Maps API 获得响应的 URL(我更改了密钥):
当我在浏览器中输入上面的 URL 时,我会返回一个 JSON (200 OK)
input 是用户提供的搜索字符串。我已将其硬编码到上面的 URL 中。
以下是我尝试过的,得到 404 错误:
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];
我还尝试了以下给出错误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]];
- 在不硬编码
inputsensorlocationkey和radius的情况下提供完整 URL 的最佳做法是什么? - 如何修复
Code=1001 "No response descriptors match the response loaded."?
【问题讨论】:
标签: json google-maps ios7 restkit restkit-0.20