grand-central-dispatch

iOS: dispatch_async and UIImageWriteToSavedPhotosAlbum

你离开我真会死。 提交于 2019-12-12 09:44:31
问题 Just learning how to allocate tasks among threads, or dispatch asynchronously. I understand that any operation that "touches" a view must be done on the main thread. What about: UIImageWriteToSavedPhotosAlbum ? I would assume this could be done on a background thread, but am I mistaken? Also, if it should be done on a background thread, is there a difference between these two calls below, as one saves a UIImage and the other saves a UIImage from a view? UIImageWriteToSavedPhotosAlbum(

UIImage initWithData: blocking UI thread from async dispatch?

那年仲夏 提交于 2019-12-12 09:28:02
问题 The following code is blocking UI (can't tap another tab until images finish loading). I have verified it is the UIImage *imageToShow = [[UIImage alloc] initWithData:data]; call that is the culprit by commenting that line out and keeping the download (which I know happens asynchronously and calls completion handler on main thread). In the case where only the initWithData: line is commented, the UI response is fine. But how can that line be the line holding up the UI if it is clearly

Symbolic breakpoint for when dispatch_async is called with a specific queue

岁酱吖の 提交于 2019-12-12 08:57:12
问题 I'm debugging an issue in my project involving grand central dispatch. In debugging this, it would be really helpful to have a way of being notified when work is dispatched to a specific queue. Is there some way of setting a symbolic breakpoint on dispatch_async with a condition that could check whether the dispatch queue argument is the same as some other queue that I have access to? 回答1: Here's how to set a conditional breakpoint. (I haven't done conditions on queues, I'm making the

What is the best way to load a remote image?

﹥>﹥吖頭↗ 提交于 2019-12-12 08:56:15
问题 I've been researching and haven't found any answer to this question - sendAsynchronousRequest vs. dataWithContentsOfURL. Which is more efficient? more elegant? safer? etc. - (void)loadImageForURLString:(NSString *)imageUrl { self.image = nil; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]

GCD serial queue does not seem to execute serially

坚强是说给别人听的谎言 提交于 2019-12-12 07:37:47
问题 I have a method that at times can be invoked throughout my code. Below is a very basic example, as the code processes images and files off of the iphone photo gallery and marks them already processed when done with the method. @property (nonatomic, assign) dispatch_queue_t serialQueue; .... -(void)processImages { dispatch_async(self.serialQueue, ^{ //block to process images NSLog(@"In processImages"); .... NSLog(@"Done with processImages"); }); } I would think that each time this method is

Asynchronous actions do not complete in order

我的梦境 提交于 2019-12-12 05:33:19
问题 I have the following swift code to allow for mapping of a users contacts to the webserver, and then show in the tableview: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) { dispatch_group_enter(self.dispatch_group) dispatch_group_async(self.dispatch_group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) { print("start 1") self.contacts = self.findContacts() dispatch_group_leave(self.dispatch_group) print("End 1") } dispatch_group_enter(self.dispatch

How to run a NSURLConnection in background in iOS

梦想的初衷 提交于 2019-12-12 05:06:04
问题 I am working with an app which is todo list organizer, where user adds notes. I am using coredata DB to store the notes. As I am providing sync feature, I am parsing JSON data to server, and also getting JSON data from server. I am using NSURLConnection API and its delegate functions - (void)pushData { loop through the notes array and send notes 1 by one [[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; [request

How To Update ProgressView in Async Thread

时间秒杀一切 提交于 2019-12-12 04:49:26
问题 I am having few doubts about Combinations of GCD and queues, in iOS. let me put those here First. According to IOS6 programming cookbook, here is small code snippet for downloading images using async and sync. and its as below dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_async (concurrentQueue, ^ { UIImage *image = nil; dispatch_sync(concurrentQueue, ^ { /* download image here */ }); dispatch_sync(dispatch_get_main_queue, ^ { /*

About calling of dispatch_queue_t and dispatch_sync

冷暖自知 提交于 2019-12-12 04:33:26
问题 Why the code if (dispatch_get_current_queue() == socketQueue) is needed? why can't we just use dispatch_sync(socketQueue, block) directly??? Thanks in advance! - (BOOL)isConnected { __block BOOL result = NO; dispatch_block_t block = ^{ result = (flags & kConnected) ? YES : NO; }; if (dispatch_get_current_queue() == socketQueue) block(); else dispatch_sync(socketQueue, block); return result; } BTW, the code is from XMPPFramework 回答1: You cannot call dispatch_sync to schedule blocks on the

How to perform sequential request with Alamofire and update a progressHUD at every step in Swift 3

假如想象 提交于 2019-12-12 04:12:16
问题 Ok, I am going nuts over this one... I'm using Alamofire 4.x (Swift 3 and XCode 8.1). I need to fetch and parse several html requests from a site that requires authentication (no json API, unfortunately). The HTML is then parsed with Fuzi and this progress can take some time so I plan to use a ProgressHUD (PKHUD to be exact) to let users know about what is going on. I also need to grab some html that is not behind an authentication. I created a struct and functions to handle the overall