Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I load images with dispatch queue for screensavers?
    text
    copied!<p>I am trying to code a screensaver that loads images from my website and displays them in a random order. The randomness and image acquiring is covered by my web API, but how to get it downloading without freezing the UI has gotten me truly stuck.</p> <p>Currently my code looks something like this:</p> <pre><code>- (void)animateOneFrame { NSRect viewBounds = [self bounds]; dispatch_queue_t queue = dispatch_get_current_queue(); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSImage *image = [self extractImageFrom:@"my_url.com"]; NSSize imageSize = [image size]; NSRect imageRect = NSMakeRect( 0, 0, imageSize.width, imageSize.height ); dispatch_sync(queue, ^{ [image drawInRect:viewBounds fromRect:imageRect operation:NSCompositeCopy fraction:1.0]; }); }); return; } </code></pre> <p>Here I tried to trigger the function that gets the image and caption on a separate queue. Then the image is to be drawn on the original view, but this is the issue.</p> <p>Whenever select the final screenviewer plugin in the preference panel, the image is drawn on the preference panel's view (not the black preview rectangle). Similarly, when previewing the screensaver the image is not drawn, but whenever I quit the screensaver the preference panel's view is covered with the image.</p> <p>It seems to me that the image is always being loaded and drawn, but not in the right queue/context? Instead of using the variable <code>queue</code> I also used <code>dispatch_get_main_queue()</code> with identical results. Any help is very appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload