AssistoLab/KVNProgress

Force KVNProgress to appear on the Main Thread

Opened this issue · 3 comments

Hey All,
I was wondering something for a while now.

KVNProgress will pretty much always crash if it's executed outside of the Main Thread.
The current solution (which seems to be a recurring answer to issues here), would be to wrap the call with a GCD Dispatch on dispatch_get_main_queue().

My question here is, why not just enforce that to begin with?
Why not have KVNProgress always display itself on the main thread, if it's not already there and avoid all of this confusion.

Even something as simple as:

if ([NSThread mainThread]) {
 // Execute as usual
} else {
  dispatch_async(dispatch_get_main_queue()) {
    // Execute as usual
  }
}

What are your thoughts on this? @kevin-hirsch

I wouldn't mind quickly making a pull request for this if there's a demand :)

@kevin-hirsch this has been open for over 2 months... Any thoughts ?

There is a great fork solving this very problem. Any chance you would consider adding this in? @kevin-hirsch :
dmsl1805@318fe74

2 years later I'm still having this problem

I've wrapped around the main thread but it still complains about updating UI on background thread

DispatchQueue.main.async {
  KVNProgress.show()
}

Apparently the problem is caused here: [self.contentView addMotionEffect:group];, maybe because dispatch_once does not run on main thread? What can we do?

KVNPrepareBlockSelf();
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
  [KVNBlockSelf setupMotionEffect];
});

I'm using swift 4.2 and the latest XCode