I'm trying to limit the number of times a user can perform an action in a month. I understand that storing a counter in NSUserDefaults
is low security as the user can easily go in and modify the stored variable, which I want to avoid. Since I don't have a server, I was thinking of using CloudKit
to store a user's possible allocated number of times along with their current count - is that even possible?
1- I've gone ahead and created a 'Record Type' called UserLimits with two int
keys: 'call_current' and 'call_limit' in the public database. Do I also need to store the user's UserRecordID as well?
2- For permissions, I've opted to set UserLimits as Read
for _world, _creator, _icloud so that no user can modify these variables.
At this point I'm kind of stuck as I can't seem to find any documentation outlining similar steps, or whether I'm doing things correctly or not.
Fetching a user's ID is as easy as:
CKContainer.default().fetchUserRecordID { recordID, error in
guard let recordID = recordID, error == nil else {
// error handling magic
return
}
print("Got user record ID \(recordID.recordName).")
}
How would I use this ID to fetch their current limit, update their count, etc? Any help would be greatly appreciated!