2012-08-15 62 views
3

我建立使用在iOS + Rails应用程序AFNetworkingAFIncrementalStore的客户端API请求,使用AFIncrementalStore默认实例为出发点:https://github.com/AFNetworking/AFIncrementalStore/tree/master/Examples/Basic%20ExampleAFNetworking不以复数我的数据模型正确对象

我的主要数据对象被称为“活动”,因此多元化的,以“活动” - 我的索引页http://localhost:3000/activities.json

不过,我可以在Xcode日志中看到,AFNetworking莫名其妙复数化,以“activitys”:

Error: Error Domain=com.alamofire.networking.error Code=-1011 
"Expected status code in (200-299), got 404" UserInfo=0x6da64a0 
{NSErrorFailingURLKey=http://localhost:3000/activitys, 
NSLocalizedDescription=Expected status code in (200-299), got 404} 

我可以改变这种行为吗?另外,我想将一个.json后缀粘贴到该URL。

回答

3

我发现在由AFIncrementalStore提供的新的Twitter例的解决方法:

// Inside "MyAPIClient.m" 

- (NSURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest withContext:(NSManagedObjectContext *)context { 
    NSMutableURLRequest *mutableURLRequest = nil; 
    if ([fetchRequest.entityName isEqualToString:@"Activity"]) { 
     mutableURLRequest = [self requestWithMethod:@"GET" path:@"activities.json" parameters:nil]; 
    } 
    return mutableURLRequest; 
}