我試圖利用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