不允许CREATE操作 [英] CREATE operation not permitted
问题描述
我正在尝试在我的iOS应用程序中使用 CloudKit
,但是当我尝试为用户$ c创建新记录时$ c>记录类型(记录类型命名为
用户
),我收到此错误:
I am trying to utilize CloudKit
in my iOS application, but when I attempt to create a new record for for a User
record type (record type is named Users
), I get this error:
<CKError 0x7fb80947ffb0: "Permission Failure" (10/2007);
server message = "CREATE operation not permitted";
uuid = 8C4C7B60-E3F4-42FC-9551-D3A76A6FF9D6;
container ID = "iCloud.com.jojodmo.Blix">
要创建新记录,我在 viewDidLoad()中使用此代码
:
UserCKManager.create(
CloudKitUser(
email: "email@website.com", password: "password", salt: "1AF4E759B20FEC32",
username: "jojodmo", posts: [], biography: "This is my bio",
firstName: "John", lastName: "Doe", flags: [],
profilePicture: UIImage(), downVotesGiven: 1, downVotesRecieved: 2,
upVotesGiven: 3, upVotesRecieved: 4, pictureProvided: false), callback: nil)
这会创建一个新的 CloudKitUser
:
init(email: String, password: String, salt: String, username: String, posts: [String], biography: String, firstName: String, lastName: String, flags: [String], profilePicture: UIImage, downVotesGiven: Int, downVotesRecieved: Int, upVotesGiven: Int, upVotesRecieved: Int, pictureProvided: Bool){
self.ready = false
record = CKRecord(recordType: "Users")
self.email = email
self.password = password
self.salt = salt
self.username = username
self.posts = posts
self.biography = biography
self.firstName = firstName
self.lastName = lastName
self.flags = flags
self.profilePicture = profilePicture
self.downVotesGiven = downVotesGiven
self.downVotesRecieved = downVotesRecieved
self.upVotesGiven = upVotesGiven
self.upVotesRecieved = upVotesRecieved
self.pictureProvided = pictureProvided
self.ready = true
}
然后尝试创建用它记录:
And then attempts to create a record with it:
class func create(user: User, callback: ((success: Bool, user: User?) -> ())?){
let ckUser = CloudKitUser(user: user)
//I've also tried using CKContainer.defaultContainer().privateCloudDatabase, and I get the same error
CKContainer.defaultContainer().publicCloudDatabase.saveRecord(ckUser.record){(record, error) in
if(error != nil){
println("An error occurred: \(error)")
callback?(success: false, user: nil)
}
else{
println("Record saved successfully")
callback?(success: true, user: ckUser)
}
}
}
我知道连接到数据库不是问题,因为我已经收到一个错误,说没有容器有我给出的ID,我修复了。
I know it isn't a problem with connecting to the database, because I have already gotten an error saying that there was no container with the ID I had given, which I fixed.
我试图在 iOS
模拟器上运行它(我已登录到iCloud上)
I am trying to run this on the iOS
simulator (I am signed into iCloud on it)
推荐答案
用户是一个特殊的记录类型已经存在于CloudKit中。你不应该自己创建记录。系统会自动为使用您应用的新用户创建记录。
您也无法创建订阅并查询Users记录类型。您只能通过ID直接查询用户记录。您可以在Users recordType中存储额外的数据,但我认为如果您将记录类型命名为其他内容会更好。
Users is a special recordType that already exist in CloudKit. You should not create records yourself. Records will be automatically created for new users that are using your app. You also can't create subscriptions and query the Users recordtype. You can only query Users records directly by ID. You can store extra data in the Users recordType, but I think in your case it would be better if you named your record type something else.
这篇关于不允许CREATE操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!