简体   繁体   中英

Cancel CloudKit Query In Progress

Is it possible to cancel a CloudKit query operation that is currently in progress, and incomplete? For example, lets say I have an app where the user enters in an email address, and then taps a search button. The app would then proceed to search through numerous stored email addresses inside a CKDatabase . If the app were to present a UIView that informed the user something like "Currently searching for (insert email address)", and also had a Cancel button in case the query took too long. Is there a way I could have the user tap that cancel button, and then execute some code to cancel the query that CloudKit is currently performing?

The reason I ask is that I have a similar situation with my iOS app that I'm currently developing. Normally everything works fine and really fast, but there have been instances where I either realized immediately that I typed the wrong email address and needed to cancel, or when I've done tests using my cell network on my iPhone, the query can take a lot longer than on wifi.

I would assume there must be a way to do this, right? Anybody that could provide an answer, or point me in the right direction would be greatly appreciated!

Assuming you are using a CKQueryOperation , you can call cancel on the operation as long as you have a reference to it.

You should then properly deal with the resulting CKErrorOperationCancelled error in the completion block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM