首先,使用responseDescriptor的inverseMapPing设置requestDescriptor,假设您有一个映射.
//This is used for mapPing responses,you already should have one of this. PS:[Data mapPing] is a method that returns an RKObjectMapPing for my model. You should create yours or use a prevIoUs created oneRKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapPing:[Data mapPing] pathPattern:nil keyPath:@"data" statusCodes:statusCodeSet];[[RKObjectManager sharedInstance] addResponseDescriptor:responseDescriptor];//Inverse mapPing,to perform a POSTRKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapPing:[[Data mapPing] inverseMapPing] objectClass:[Data class] rootKeyPath:nil];[[RKObjectManager sharedInstance] addRequestDescriptor:requestDescriptor];
之后,要执行POST,只需调用下面的方法即可. Restkit将获取您尝试发布的实例,将其序列化并发送到所选路径.
[[RKObjectManager sharedInstance] postObject:instanceOfYourModel path:yourPathHere parameters:nil success:^(RKObjectRequestoperation *operation,RKMapPingResult *mapPingResult) { NSLog(@"Success");} failure:^(RKObjectRequestoperation *operation,NSError *error) { NSLog(@"Error");}];
如果您没有映射模型,请告诉我们,以便我们可以尝试其他方法.
总结以上是内存溢出为你收集整理的ios – RESTKit POST请求教程全部内容,希望文章能够帮你解决ios – RESTKit POST请求教程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)