How to test Long-Lived Operations

I am trying to test long-lived CKOperations in my CloudKit app. What seems to be happening is that, for my CKModifyRecordsOperation with longLived flag is Yes, the longLivedOperationWasPersistedBlock is being called correctly, but after quitting the app and then restarting it, the fetchAllLongLivedOperationIDsWithCompletionHandler doesn't return any operationIDs, even though if I save the operationID manually and then fetch using fetchLongLivedOperationWithID, it returns a valid operation that shows that it is "outstanding":

<CKModifyRecordsOperation: 0x101d0e340; operationID=5D9A254E4C3E3C41, long-lived, outstanding, qos=UserInteractive>


I have tried a couple of different things:

- I set a breakpoint in perRecordCompletionBlock, verify that it is called after longLivedOperationWasPersistedBlock completes (but before modifyRecordsCompletionBlock), and then kill the debugger at that point

- I set the same breakpoints, but instea dof killing debugger, I close the app by swiping up on the app-switcher screen

- I've tried without the debugger, just used the app to upload something large (8MB) and quit, and then restarted with the debugger

None of these seems to work. Any ideas why? The only detail I am aware of is that fetchAllLongLivedOperationIDsWithCompletionHandler shiould be called, which it is!


Thanks.

Replies

To respond to my own question: turns out that fetchAllLongLivedOperationIDsWithCompletionHandler doesn't return anything e ven if there are pending long-lived operations... not sure why. It works better if I track and archive the long-lived operationID using it's completionBlock (and remove it from local archive if the operation completed successfully while the app was running) ... at app launch, using fetchLongLivedOperationWithID to fetch with the operationID works successfully. To test this, I use an CKModifyOperation with a CKRecord which has a CKAsset ... and quiting the app after the 'longLivedOperationWasPersistedBlock' completed.

I'm unable to test long lived operations as well (I'm using the simulator). I set a break point in the block:


  
            [someOp setLongLivedOperationWasPersistedBlock:^{
                NSLog(@"Long lived persisted: %@",someOp.operationID); //<-- break point hit here
            }];


When i hit the breakpoint, I kill the app. On next launch I call -fetchLongLivedOperationWithID:completionHandler: and pass in the the string that logged out. I get no operations. Any ideas on how can we test this stuff?