- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在使用 RestKit 0.20pre6 发布 NSManagedObject 时遇到问题,它导致在我的 Rails 站点上创建一个值为 nil 的条目。我怀疑映射器,但据我所知,我已经正确设置了 RK 对象。例子很少,支持有限。该示例涉及 NSObjects 而不是 CoreData,因此我不得不做出一些假设。
这是我发布的代码,后面是控制台输出。该应用程序可以正常从服务器获取对象。
// Sync the added object to the server
// ****************************************
RKObjecMapping *responseMapping = [RKObjectMapping mappingForClass:[Event class]];
// RKEntityMapping *responseMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:self.managedObjectStore];
[responseMapping addAttributeMappingsFromDictionary:@{
@"id": @"eventId",
@"name": @"name",
@"amount": @"amount",
@"length": @"length",
@"updated_at": @"updatedAt",
@"created_at": @"createdAt",
@"latitude": @"latitude",
@"longitude": @"longitude",
@"thumbnail": @"thumbnail",
@"airTemp": @"airTemp",
}];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *eventDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
pathPattern:@"/events"
keyPath:@"events"
statusCodes:statusCodes
];
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; // objectClass == NSMutableDictionary
[requestMapping addAttributeMappingsFromDictionary:@{
@"id": @"eventId",
@"name": @"name",
@"amount": @"amount",
@"length": @"length",
@"updated_at": @"updatedAt",
@"created_at": @"createdAt",
@"latitude": @"latitude",
@"longitude": @"longitude",
@"thumbnail": @"thumbnail",
@"airTemp": @"airTemp",
}];
// For any object of class Article, serialize into an NSMutableDictionary using the given mapping and nest
// under the 'article' key path
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping
objectClass:[Event class]
rootKeyPath:@"events"
];
LocationsAppDelegate *appDelegate = (LocationsAppDelegate *)[[UIApplication sharedApplication] delegate];
// RKObjectManager *manager = [RKObjectManager managerWithBaseURL:gBaseURL];
[RKObjectManager sharedManager].requestSerializationMIMEType = RKMIMETypeJSON;
[[RKObjectManager sharedManager] addRequestDescriptor:requestDescriptor];
[[RKObjectManager sharedManager] addResponseDescriptor:eventDescriptor];
NSLog(@"RVC-addEvent %@ - %@", appDelegate.user.login, appDelegate.user.password);
[[NBEventManager sharedManager] setUsername:appDelegate.user.login andPassword:appDelegate.user.password];
appDelegate.objectManager.HTTPClient = [NBEventManager sharedManager];
event = [eventsArray objectAtIndex:0];
[[RKObjectManager sharedManager] postObject:event
path:@"/events"
parameters:nil
success:nil
failure:nil
];
}
2013-01-15 23:25:52.857 fish[38803:13403] I restkit.network:RKHTTPRequestOperation.m:152 POST 'http://localhost:3000/events' 2013-01-15 23:25:52.969 fish[38803:16903] I restkit.network:RKHTTPRequestOperation.m:179 POST 'http://localhost:3000/events' (201 Created) [0.1121 s] 2013-01-15 23:25:52.971 fish[38803:17507] D restkit.object_mapping:RKMapperOperation.m:360 Executing mapping operation for representation: { event = { airTemp = ""; amount = ""; "created_at" = "2013-01-16T04:25:52Z"; id = 54; latitude = ""; length = ""; longitude = ""; name = ""; thumbnail = ""; "updated_at" = "2013-01-16T04:25:52Z"; "user_id" = ""; }; } and targetObject: (entity: Event; id: 0x9c7f710 ; data: { airTemp = 0; amount = nil; createdAt = "2013-01-16 04:25:52 +0000"; eventId = 0; latitude = "28.158466"; length = 0; longitude = "-82.509215"; name = nil; photo = nil; thumbnail = nil; updatedAt = nil; }) 2013-01-15 23:25:52.971 fish[38803:17507] D restkit.object_mapping:RKMapperOperation.m:287 Found mappable data at keyPath 'event': { airTemp = ""; amount = ""; "created_at" = "2013-01-16T04:25:52Z"; id = 54; latitude = ""; length = ""; longitude = ""; name = ""; thumbnail = ""; "updated_at" = "2013-01-16T04:25:52Z"; "user_id" = ""; } 2013-01-15 23:25:52.971 fish[38803:17507] D restkit.object_mapping:RKMapperOperation.m:232 Asked to map source object { airTemp = ""; amount = ""; "created_at" = "2013-01-16T04:25:52Z"; id = 54; latitude = ""; length = ""; longitude = ""; name = ""; thumbnail = ""; "updated_at" = "2013-01-16T04:25:52Z"; "user_id" = ""; } with mapping eventId>", " name>", " amount>", " length>", " updatedAt>", " createdAt>", " latitude>", " longitude>", " airTemp>", " thumbnail>" )> 2013-01-15 23:25:52.971 fish[38803:17507] D restkit.object_mapping:RKMappingOperation.m:754 Starting mapping operation... 2013-01-15 23:25:52.972 fish[38803:17507] D restkit.object_mapping:RKMappingOperation.m:818 Finished mapping operation successfully... 2013-01-15 23:25:52.973 fish[38803:17507] D restkit.object_mapping:RKMapperOperation.m:316 Found unmappable value at keyPath: events 2013-01-15 23:25:52.973 fish[38803:17507] D restkit.object_mapping:RKMapperOperation.m:389 Finished performing object mapping. Results: { event = " (entity: Event; id: 0x9c7f710 ; data: {\n airTemp = nil;\n amount = nil;\n createdAt = \"2013-01-16 04:25:52 +0000\";\n eventId = 54;\n latitude = nil;\n length = nil;\n longitude = nil;\n name = nil;\n photo = nil;\n thumbnail = nil;\n updatedAt = \"2013-01-16 04:25:52 +0000\";\n})"; } 2013-01-15 23:25:52.973 fish[38803:13403] D restkit.core_data:RKManagedObjectRequestOperation.m:534 Skipping deletion of orphaned objects: only performed for GET requests. 2013-01-15 23:25:52.976 fish[38803:11f03] D restkit.core_data:RKManagedObjectRequestOperation.m:599 Refreshing mapped target object (entity: Event; id: 0x9c7f710 ; data: { airTemp = nil; amount = nil; createdAt = "2013-01-16 04:25:52 +0000"; eventId = 54; latitude = nil; length = nil; longitude = nil; name = nil; photo = nil; thumbnail = nil; updatedAt = "2013-01-16 04:25:52 +0000"; }) in context
现在这是我的代码,因为我已将所有映射移至应用程序委托(delegate)并已实现 RKEntityMapping。我仍然没有 JSON 对象附加到 POST 调用。
RKEntityMapping *eventMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:managedObjectStore];
[eventMapping addAttributeMappingsFromDictionary:@{
@"id": @"eventId",
@"name": @"name",
@"amount": @"amount",
@"length": @"length",
@"updated_at": @"updatedAt",
@"created_at": @"createdAt",
@"latitude": @"latitude",
@"longitude": @"longitude",
@"thumbnail": @"thumbnail",
@"airTemp": @"airTemp",
}];
eventMapping.identificationAttributes = @[ @"eventId" ];
//RKRelationshipMapping *eventRelationship = [RKRelationshipMapping relationshipMappingFromKeyPath:@"events"
// toKeyPath:@"events"
// withMapping:eventMapping];
//[eventMapping addPropertyMapping:eventRelationship];
// Register our mappings with the provider
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:eventMapping
pathPattern:nil
keyPath:@"event"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
RKEntityMapping *eventRequestMapping = [eventMapping inverseMapping];
RKRequestDescriptor *eventRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:eventRequestMapping
objectClass:[Event class]
rootKeyPath:@"event"
];
[objectManager addRequestDescriptor:eventRequestDescriptor];
[RKObjectManager sharedManager].requestSerializationMIMEType = RKMIMETypeJSON;
最佳答案
RESTKit 0.20pre6 中有一个错误,即使它是一个对象,它也会将 POST 请求的 HTTP Body 打印到 NSLog 为(null)。我在开发分支中修复了它。 https://github.com/RestKit/RestKit/pull/1139
关于iphone - 使用 RestKit 发布导致发布 nil 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14351531/
我使用 RestKit 与 REST api 进行交互。对于某些操作,例如 HTTP PUT/POST/DELETE,我只关心响应状态代码(200 或 500 等),而不关心响应数据,即使 API 确
我在客户端和服务器端都有一个这样的响应对象: 客户端: //BaseResponse.h @interface BaseResponse : NSObject{ NSString *code;
我正在尝试将 RestKit 0.20 集成到我的项目中,例如,我使用 google rss 阅读器作为示例项目。 这是对 Xml 的响应 / /类别> & 这是我必须从中获取数据的 Xml。 RKO
我很难使用 CocoaPods 将 RestKit 安装到我的项目中。我收到未找到的错误。 我的 Pods.xcconfig 看起来像这样: GCC_PREPROCESSOR_DEFINITIONS
大多数 RESTful API 都会路由对资源的访问,例如 Rabbit 对象,如下所示: GET /rabbits <--- GET all rabbits.
问题 在 iOS 上完成 Restkit 的安装说明后,我收到 Apple Mach-o 链接器错误: 我的流程 我尝试按照此处的 Restkit 安装说明进行操作:https://github.co
我完全按照此处找到的这些步骤操作: http://www.raywenderlich.com/13097/intro-to-restkit-tutorial 但是....我得到了错误: 这可能是什么原
我正在尝试使用 RestKit 调用需要基本身份验证的端点。 RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[JSNCateg
我想用RestKit ,但我已经使用 Realm.io而不是 CoreData。 是否可以在 Realm.io 之上使用 RestKit? 最佳答案 你当然可以。从 RestKit 取回对象后: //
我没有找到任何方法来设置 restkit 0.20.0 的超时间隔。 任何人都可以帮助增加超时间隔。 谢谢 最佳答案 子类 RKHTTPRequestOperation 和实现方法 - (NSURLR
我正在尝试实现 RESTKit 0.20 操作队列,我在博客上读到 NSOperationQueue 也可用于创建操作队列。我想使用 RestKit 操作队列的 native 方法。 任何人都可以发布
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
我在这里做的事情很奇怪吗? 我的类别得到下载和映射, 产品也像日志记录所说的那样被下载和映射, 但是我的产品在每个分类下都是空的,谢谢! { "productsCategories" : [
我尝试了几乎所有的解决方案,但都不适合我。我在 Xcode 6 上收到此错误。我也更新了 cocoa pod ,也更新了 pod 文件。 安装更新后,我在下面添加了几行: [!] From now o
我正在尝试使用 Jenkins-CI 自动构建一个使用 Restkit 的 iOS 项目,显然,restkit 作为一个项目驻留在主项目中。该项目使用 XCode-IDE 成功构建。 但是当我使用 x
我在 Xcode 6.1 中开发项目。它工作正常,突然提示错误“未找到 Restkit/Restkit.h 文件”。从 $ 更改Architectures 后出现错误(ARCHS_STANDARD_3
我按照 github 上的说明进行操作页面但有问题(肯定是我:P)但是,您知道在 Xcode4 RestKit 中集成/使用的任何好的教程吗? 谢谢! 最佳答案 从此链接下载最新版本 http://r
我在尝试让 RestKit 构建和工作时遇到了麻烦。我收到可怕的“词法或预处理器问题:未找到 RestKit/RestKit.h 文件”消息。我使用 Xcode 4.2,我的项目适用于 iOS。 早些
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:BASE_URL]]; PPPS
有没有办法使用对象管理器访问请求的成功块中的响应数据? [objectManager postObject:[User class] path:@"/users" parameters:nil suc
我是一名优秀的程序员,十分优秀!