我试图利用CloudKit
在我的iPhone应用程序,但是当我试图创建一个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 protected]", 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中就可以了)
这似乎是一个权限问题。你可以直接用同一个用户访问数据库吗?如果是这样,你可以创建你的记录直接访问?我相信第一个答案是肯定的,第二个答案是否定的。您需要为数据库用户创建权限。 – 2014-12-19 06:22:37
@LajosArpad第一个答案是肯定的,但第二个答案IS也不是,我怎样才能给数据库用户创建权限?我觉得我会试图,如果我知道如何 – Jojodmo 2014-12-19 06:36:30