【发布时间】:2015-02-18 01:40:06
【问题描述】:
我尝试在我的 iOS 应用程序中使用 CloudKit,但是当我尝试为 User 记录类型(记录类型名为 Users)创建新记录时,我收到此错误:
<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
}
然后尝试用它创建一条记录:
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 的容器,我已修复。
我正在尝试在 iOS 模拟器上运行它(我已登录 iCloud)
【问题讨论】:
-
这似乎是一个权限问题。您可以使用同一用户直接访问数据库吗?如果是这样,您可以通过直接访问创建您的记录吗?我相信第一个答案是肯定的,第二个答案是否定的。您需要授予数据库用户创建权限。
-
@LajosArpad 第一个答案是肯定的,但第二个答案也是否定的,我怎样才能给数据库用户创建权限?如果我知道如何,我觉得我会尝试这样做
-
可能的答案是设置此处描述的创建权限:stackoverflow.com/a/56733008/1807644
标签: ios swift ios8 icloud cloudkit