我无法使用以下代码发布数据。我已经试过所有相关的帖子了,但还是不能让它工作。
在请求描述符中添加,使用nsdictionary映射参数,尝试反向映射等。
var parms = WearRequestParms()
parms.Height = height
parms.Width = width
parms.Density = density
if let userId = AlpineMetricsHttpClient.GetUserId()
{
parms.UserId = userId
}
var objectManager : RKObjectManager?
objectManager = AlpineMetricsHttpClient.SetupClient()
// var mapping = RKObjectMapping(forClass:WearRequestParms.self)
var mapping = RKObjectMapping.requestMapping()
let requestMappingObjects = ["IsCircle","Height","Width","Density","UserId","WearModel","Platform"]
let dict : NSMutableDictionary = ["IsCircle":"IsCircle","Height":"Height","Width":"Width","Density":"Density","UserId":"UserId","WearModel":"WearModel","Platform":"Platform"]
mapping.addAttributeMappingsFromArray(requestMappingObjects)
// mapping.addAttributeMappingsFromDictionary(dict as [NSObject : AnyObject])
// var newRequestMapping = mapping.inverseMapping()
let requestDescriptor = RKRequestDescriptor(mapping: mapping, objectClass: WearRequestParms.self, rootKeyPath: "", method: RKRequestMethod.POST)
objectManager!.addRequestDescriptor(requestDescriptor)
// response
let responseMapping = RKObjectMapping(forClass:PostStatus.self)
var responseDescriptor = RKResponseDescriptor(
mapping: responseMapping
,method:RKRequestMethod.POST
,pathPattern : "/api/User/RegisterWearDevice"
,keyPath :""
,statusCodes : NSIndexSet(index:200))
objectManager!.addResponseDescriptor(responseDescriptor)
RKObjectManager.sharedManager().postObject(parms, path: "/api/User/RegisterWearDevice", parameters: nil,
success:{ operation, mappingResult in
NSLog("success")
defaults.setBool(true, forKey: "WearDimensionsSynced")
},
failure:{ operation, error in
NSLog("Error loading metric list': \(error!.localizedDescription)")
//return nil
}
);
最佳答案
我不应该使用rkobjectmanager.sharedmanager().postObject
这导致先前的值被覆盖或干扰。
我换了
RKObjectManager.sharedManager().postObject
用
objectManager!.postObject
关于swift - Swift RestKit Post不包括发布数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29631664/