我有一个使用 Ray Wenderlich SDSyncEngine 和 SDAFParseAPIClient 的应用程序,但我已对其进行了修改以使用我客户的 Web 服务。创建获取请求时,它使用字符串附加到指定仅在更新日期之后下载记录的 GET。我在这里记录:
-[SDAFParseAPIClient GETRequestForAllRecordsOfClass:updatedAfterDate:] [Line 69] jsonString = {"updatedAt":{"$gte":{"__type":"Date","iso":"1900-01-01T00:00:00.999Z"}}}
-[SDAFParseAPIClient GETRequestForClass:parameters:] [Line 54] request <NSMutableURLRequest http://myserver.com/api_address_which_returns_XML_JSON?where=%7B%22updatedAt%22%3A%7B%22%24gte%22%3A%7B%22__type%22%3A%22Date%22%2C%22iso%22%3A%221900-01-01T00%3A00%3A00.999Z%22%7D%7D%7D>
该字符串由以下方法生成:
- (NSMutableURLRequest *)GETRequestForAllRecordsOfClass:(NSString *)className updatedAfterDate:(NSDate *)updatedDate {
NSMutableURLRequest *request = nil;
NSDictionary *paramters = nil;
if (updatedDate) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.'999Z'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *jsonString = [NSString
stringWithFormat:@"{\"updatedAt\":{\"$gte\":{\"__type\":\"Date\",\"iso\":\"%@\"}}}",
[dateFormatter stringFromDate:updatedDate]];
NSLog(@"jsonString = %@", jsonString);
paramters = [NSDictionary dictionaryWithObject:jsonString forKey:@"where"];
}
request = [self GETRequestForClass:className parameters:paramters];
return request;
}
最初来自教程。我的网络服务不在字典中使用 iso 格式的日期。所以我将代码更改为:
NSString *jsonString = [NSString stringWithFormat:@"{\"updatedAt\":%@}",
[dateFormatter stringFromDate:updatedDate]];
得到了这个:
jsonString = {"updatedAt":1900-01-01T00:00:00.999Z}
但由于某种原因它不起作用,我仍然每次都从 Web 服务获取所有记录。