gpt4 book ai didi

Swift RestKit Post 不包括发布数据

转载 作者:可可西里 更新时间:2023-11-01 02:23:10 26 4
gpt4 key购买 nike

我无法使用以下代码获取发布的数据。我已经尝试了 SO 上的所有相关帖子,但仍然无法正常工作。

在请求描述符中添加,具有用于映射参数的 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
}
);

最佳答案

我不应该使用 RKObjectManager.sharedManager().postObject

这导致以前的值被覆盖或干扰。

我换了

RKObjectManager.sharedManager().postObject

objectManager!.postObject

关于Swift RestKit Post 不包括发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29631664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com