gpt4 book ai didi

swift - 为什么我的代码没有将数据保存到 Kinvey 后端?

转载 作者:行者123 更新时间:2023-11-30 13:31:09 24 4
gpt4 key购买 nike

我有一个 viewController,它具有三个文本字段(姓名、电子邮件和座位)和一个日期选择器。下面有一个按钮,作为导出连接,用于将预订发送到应注册的后端。我已经尝试了几件事,但由于某种原因,数据没有保存。我已连接到后端,因为我可以看到 Api 调用和数据存储(以字节为单位)...您可以检查我的代码吗?

    override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

self.sendReservation.addTarget(self, action: "sendBooking:", forControlEvents: .TouchUpInside)

let reservation = Booking()
reservation.name = userName.text
reservation.email = userEmail.text
reservation.seats = userSeat.text
reservation.date = NSDate(timeIntervalSince1970: 1352149171) //sample date

func sendBooking (sender: UIButton) {

KCSUser.loginWithUsername("admin", password: "leden1234",
withCompletionBlock: { (user: KCSUser!, errorOrNil: NSError!, result: KCSUserActionResult) -> Void in
if errorOrNil == nil {

let store = KCSAppdataStore.storeWithOptions([
KCSStoreKeyCollectionName : "userReservation",
KCSStoreKeyCollectionTemplateClass : Booking.self
])

store.saveObject(
reservation,
withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in
if errorOrNil != nil {
//save failed
NSLog("Save failed, with error: %@", errorOrNil.localizedFailureReason!)
} else {
//save was successful
NSLog("Successfully saved event (id='%@').", (objectsOrNil[0] as! NSObject).kinveyObjectId())
}
},
withProgressBlock: nil
) } else {

NSLog("User was not registered: %@", errorOrNil.localizedFailureReason!)

}

})
}
}

}

最佳答案

所有 Kinvey 请求都必须使用授权用户发出,如果用户不存在,则存在自动用户生成工具。

确保您是活跃用户,即您在进行任何 Kinvey 调用之前已登录。我已尝试过您的代码,效果很好。尝试以下实现:

KCSUser.loginWithUsername(
"kinvey",
password: "12345",
withCompletionBlock: { (user: KCSUser!, errorOrNil: NSError!, result: KCSUserActionResult) -> Void in
if errorOrNil == nil {

//the log-in was successful and the user is now the active user and credentials saved
// Put your code to save the object here

} else {

//there was an error with the update save

}
}
)

更多详情请查看http://devcenter.kinvey.com/ios/guides/users# .

如果上述信息没有帮助,请告诉我您在“errorOrNil.localizedFailureReason”中遇到的错误。

关于swift - 为什么我的代码没有将数据保存到 Kinvey 后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572229/

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