GCD and OSSpinLockLock
my tought is that some timeout or failure blocks your gcd queues for too much time. try rewriting that code with NSOperationQueue
, that way you can stop the queue on errors or view/controller going away.
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/NSOperationQueue_class/index.html
Update 1:
Here is my trial at your code, i added queue and logs, check them and also check the timeout value. This way if a request does not finish (most likely) you can trace it. All requests are serial so if one of them stops you should immediately notice it.
You can create more than one queue and access them sequentially (round robin) to have more requests simultaneously. I would not go with more than 4 queues which is also the default for most desktop internet browsers.
// keep the same queue for all request (class member?), don't put it in the same block
NSOperationQueue* queue= [[NSOperationQueue alloc] init];
// keep this in another code block from queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^(void) {
[[InstagramEngine sharedEngine] getMediaAtLocation:location count:kInstagramLocationBufferSize maxId:nil withSuccess:^(NSArray* media, InstagramPaginationInfo* paginationInfo) {
if (media && media.count>0) {
for (InstagramMedia* mediaObject in media) {
NSURL* url= mediaObject.standardResolutionImageURL;
NSLog(@"Start loading from %@", url);
NSURLRequest* req= [NSURLRequest requestWithURL:mediaObject.standardResolutionImageURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30]; // 30 seconds timeout
[NSURLConnection sendAsynchronousRequest:req queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"Stop loading from %@ %@ %@", url, response, connectionError);
if (data != nil && connectionError == nil) {
UIImage* img = [UIImage imageWithData:data];
if (img) {
// if you are triggering some ui update run on main thread
// [self.locationBuffer addObject:img];
[self.locationBuffer performSelectorOnMainThread:@selector(addObject:)
withObject:img
waitUntilDone:NO];
}
}
}];
}
}
} failure:^(NSError *error) {
NSLog(@"Error getting media list: %@", error);
}];
});
What does toast mean?
A small informational message that pops up like toast.
http://en.wikipedia.org/wiki/Toast_(computing)
Related Topics
Left-Align Image and Center Text on Uibutton
How to Add a Uitoolbar Programmatically to an iOS App
Sendasynchronousrequest Was Deprecated in iOS 9, How to Alter Code to Fix
How to Know If Nsassert Is Disabled in Release Builds
New Foursquare Venue Detail Map
Ipad: Drag a Uitableviewcell from One Uitableviewcontroller and Drop It into Another
How to Add a Footer to a Uitableview in Storyboard
Move a View When Scrolling in Uitableview
Expanding and Collapsing Table View Cells in iOS
Show Search Bar in Navigation Bar Without Scrolling on iOS 11
--Resource-Rules Has Been Deprecated in MAC Os X >= 10.10
How to Use Cocoapods When Creating a Cocoa Touch Framework
Wkwebview Didn't Finish Loading, When Didfinishnavigation Is Called - Bug in Wkwebview
How to Deselect a Segment in Segmented Control Button Permanently Till Its Clicked Again
Uisearchbar Change Placeholder Color
Making Video from Uiimage Array with Different Transition Animations