2
我無法使用以下代碼發佈數據。我已經嘗試過所有相關的帖子,但仍然無法實現。Swift RestKit發佈不包括髮布數據
在請求描述符中添加了NSDictionary用於映射參數,嘗試了inverseMapping等。
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
}
);
以什麼方式?你的意思是你有多個經理,所以你應該使用'objectManager'而不是'RKObjectManager.sharedManager'? – Wain
@更正確的是,我更新了我的回答,並轉換了我的內容。 – TWilly