Post

Replies

Boosts

Views

Activity

Cycle detected in CKModifyRecordsOperation when trying to bulk save
I'm working to refactor a somewhat clunky iterative save loop for CloudKit to use CKModifyRecordsOperation and bulk save records. I have a Course, which has 1+ Weeks, each which has 1+ Lessons. Previously I'd create the Course in CloudKit, then create the Weeks, then the Lessons and circle back to update the Weeks with the Lesson references once created. And also fetch and save the Course record with the references to the Weeks once Weeks were created. I've refactored to create all (Course, Week and Lesson) records locally, with the relevant references set up. E.g., course["weeks"] contains the record references for each week I've created locally, for example: course["weeks"] = getWeekRefsForCourse(for: allWeeks) func getWeekRefsForCourse(for allWeeks: [CKRecord]) -> [CKRecord.Reference] { var weekRefsArray: [CKRecord.Reference] = [] for each in allWeeks { let weekRef = CKRecord.Reference(record: each, action: .deleteSelf) weekRefsArray.append(weekRef) return weekRefsArray } The issue is when I go to save, the error I get back is: Invalid list of records: Cycle detected in record graph This suggests that I've got a record referring to itself, but I've gone record by record and I I can't see anything. The Weeks reference the Course and the Lessons, but not themselves, etc. So my only theory is that because I'm trying to save items that refer to other items that haven't yet been created, what I'm trying to do isn't possible. Is the correct protocol here actually my original approach? Or is there something I'm missing? Original approach: Save Course Save Week Save Lessons Update Weeks with Lesson references Update Course with Week references CKModifyRecordsOperation code: 		let bulkSaveQueryOp = CKModifyRecordsOperation() 		bulkSaveQueryOp.recordsToSave = [courseRecord] 		bulkSaveQueryOp.recordsToSave?.append(contentsOf: weeks) 		bulkSaveQueryOp.recordsToSave?.append(contentsOf: lessons) 		//note I've confirmed I have the correct number of records 		bulkSaveQueryOp.modifyRecordsCompletionBlock = { records, recordIDs, error in 		if let error = error as? CKError { 					log.error(error) 			 } else { // success } 		} 		CKContainer.default().publicCloudDatabase.add(bulkSaveQueryOp)
1
0
524
Sep ’20
Issue checking if user is logged into CloudKit
I've got an iOS app that is reliant on cloudkit for much of the functionality. However, I seem to be able to get in a state where the user is partially logged in. Basic cloudkit login checks pass, I can get my recordID, but I can't read or write to records like I can when I'm fully logged in. Full details below - any ideas on how to identify this state without testing a read or write? Upon launch of the phone, I get an 'Update Apple ID Settings' alert that states "Some account services will not be available until you sign in again" So, the issue is clearly related to that (which seems to be frequent with the simulator...). If I got to my settings and re-enter my password, all is well with the world. I can deal with this by error handling on an attempt to read or write, but I'd rather check in advance and warn the user appropriately. How I check today: At launch, I check to see if the user is logged in to cloudkit: 		if FileManager.default.ubiquityIdentityToken != nil { 				print("User logged in") // IT PASSES IN THIS STATE 		} 		else { 				print("User is not logged in") 		} So far, so good. The test passes, the user is logged in. However, when I go to read or write, it is clear that I'm NOT logged in. For example, I'll get a CKErrorPermissionFailure when trying to write. Additional note - in the current, 'partially'? logged in state, the below returns the correct recordID for my user: let container = CKContainer.default() container.fetchUserRecordID() { recordID, error in Any ideas on how to programatically identify this partial state for cloudkit? Thanks!
0
0
498
Aug ’20
Cloudkit schema - changes not loading for deploy
I've got a cloudkit schema working on a development environment.When I go to deploy to production, as I've done in the past, this time it gets hung on the 'Loading Changes' spinner on the 'Confirm Deployment' screeen. It loads fine for all other apps. I've even gone in and made an additional change to the dev scheme on the off change that the existing pending changes weren't registering as differential - but no luck. I can't get it to go off the 'Loading Changes' spinner.Ideas??Thanks!Steve
3
0
974
Apr ’20