我有一个iOS + Rails 3.1应用程序,我正在使用 AFIncrementalStore 进行客户端 - 服务器通信。这是一种日历应用程序,Activity
是主要模型。
当我使用Rails Web表单创建新的 Activity 时,服务器会收到:
Started POST "/activities" for 127.0.0.1 at 2013-06-21 22:38:04 +0200
Processing by ActivitiesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"pruaVLfUijjNrYfh17yJmQgYLrnrA713OjgdayudZAg=", "activity"=>{"text"=>"Test från web", "starts_at_formatted"=>"23:00"}, "commit"=>"Create Activity"}
但是当我从我的iOS应用发布时,它看起来像这样:
Started POST "/activities" for 127.0.0.1 at 2013-06-21 22:36:10 +0200
Processing by ActivitiesController#create as JSON
Parameters: {"activityID"=>"0", "auth_token"=>"xkT2eqqdoNp5y4vQy7xA", "ends_at"=>nil, "starts_at"=>"2013-06-21T22:36:10+0200", "text"=>"Inserted!", "updated_at"=>nil}
WARNING: Can't verify CSRF token authenticity
即。我错过了包含 Activity 数据的"activity"=> {...}
位。我如何实现这一目标,是否需要在representationOfAttributes
子类中对AFRESTClient <AFIncrementalStoreHTTPClient>
进行大规模的改造?
答案 0 :(得分:0)
您需要在-representationOfAttributes:ofManagedObject:
子类中实现AFRestClient
以包装默认返回的字典。
如果默认属性映射已经起作用,可能就像这样简单:
- (NSDictionary *)representationOfAttributes:(NSDictionary *)attributes ofManagedObject:(NSManagedObject *)managedObject
{
return @{[managedObject.entity.name lowercaseString]: [super representationOfAttributes:attributes ofManagedObject:managedObject]};
}
如果您需要进行一些自定义属性映射,请执行此操作以代替我对super
的调用。