Actually it was wrong way. And i changed my method. I did it with NSURLSession
. it has method that is named invalidateAndCancel
. if i use this method my session
is canceled and fetching
is stoped.
- (void) pressedFetch
{
NSString *jsonUrl = @"http://api.geonames.org/postalCodeLookupJSON?postalcode=6600&country=AT&username=demo";
NSURL *url = [NSURL URLWithString:str];
NSURLSessionConfiguration *conf = [NSURLSessionConfiguration ephemeralSessionConfiguration];
session = [NSURLSession
sessionWithConfiguration:conf
delegate:self
delegateQueue:[NSOperationQueue mainQueue]];
task = [session downloadTaskWithRequest:request]; //NSURLSessionDownloadTask *task = ...
[task resume];
}
- (void) pressedStop
{
[session invalidateAndCancel]; //NSURLSession *session = ...
}
it was so easy )))