I've found quite a lot of posts related to this topic, nevertheless I might keep doing something wrong...
After creating query
, an instance of PFQuery, the request is implemented as query.findObjects()
(runs on a background thread). During that request I'm not able to cancel its process like I would expect from the method query.cancel()
.
Scenario: Internet connection is missing, query.findObjects()
tries to connect, fails, tries again. I implemented query.cancel()
that is executed when the request first fails (in the if objects == nil
that is executed at the mentioned point), still it is going for a second try. After the second try - each of those take around 15 seconds - has failed, it doesn't trigger a third.
Why does this happen, why is the process not interrupted when calling query.cancel()
?
Thanks for any help!
EDIT 1: Some code
func getPost() {
let queue = dispatch_queue_create("SerialBgQueue", DISPATCH_QUEUE_SERIAL)
dispatch_async(queue, {
var query = PFQuery(className: "Post")
var objects = query.findObjects()
if objects != nil {
// do something
} else {
println("This part is executed now")
// doesn't stop the ongoing (second) connection attempt:
query.cancel()
// do something
return
}
})
}
EDIT 2: That's the logs - to me it looks like a second bundle of attempts, check the logs (attempt 2, 3, 4, ... then starting again 2, 3, 4, ...). The else {
-part is executed once in between and a second time in the very end. After that, everything has stopped, no more "attempts".
2014-10-08 13:37:10.104 Instagram[9210:391955] Error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x7fe708c545c0 {NSUnderlyingError=0x7fe708c53020 "The Internet connection appears to be offline.", NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=The Internet connection appears to be offline.} (Code: 100, Version: 1.3.0)
2014-10-08 13:37:10.105 Instagram[9210:391952] Network connection failed. Making attempt 2 after sleeping for 1.092226 seconds.
2014-10-08 13:37:11.311 ... (Code: 100, Version: 1.3.0) // same Error like in the very first line
2014-10-08 13:37:11.312 Instagram[9210:391945] Network connection failed. Making attempt 3 after sleeping for 2.184451 seconds.
2014-10-08 13:37:13.704 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:13.704 Instagram[9210:391952] Network connection failed. Making attempt 4 after sleeping for 4.368902 seconds.
2014-10-08 13:37:18.514 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:18.514 Instagram[9210:391952] Network connection failed. Making attempt 5 after sleeping for 8.737804 seconds.
2014-10-08 13:37:27.257 ... (Code: 100, Version: 1.3.0)
This part is executed now
2014-10-08 13:37:27.265 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:27.266 Instagram[9210:392183] Network connection failed. Making attempt 2 after sleeping for 1.387503 seconds.
2014-10-08 13:37:28.792 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:28.793 Instagram[9210:392202] Network connection failed. Making attempt 3 after sleeping for 2.775006 seconds.
2014-10-08 13:37:31.843 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:31.844 Instagram[9210:392205] Network connection failed. Making attempt 4 after sleeping for 5.550011 seconds.
2014-10-08 13:37:37.401 ... (Code: 100, Version: 1.3.0)
2014-10-08 13:37:37.401 Instagram[9210:392202] Network connection failed. Making attempt 5 after sleeping for 11.100023 seconds.
2014-10-08 13:37:49.050 ... (Code: 100, Version: 1.3.0)
This part is executed now