Tried to obtain the web lock from a thread other than the main thread or the web thread. Crashing now

前端 未结 6 1407
轮回少年
轮回少年 2020-12-10 01:03

bool _WebTryThreadLock(bool), 0x8053ce0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UI

相关标签:
6条回答
  • 2020-12-10 01:41

    I had a similar issue and used

    performSelectorOnMainThread:withObject:waitUntilDone:
    

    to solve it. Hope that helps.

    0 讨论(0)
  • 2020-12-10 01:42

    I too faced this issue while i was calling a method by

    [self performSelector:@selector(myMethod) withObject:nil afterDelay:.01];
    

    Now it has solved by performing it on main thread

    [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:NO];
    
    0 讨论(0)
  • 2020-12-10 01:45

    if you are going to do any UI operation it has to be done on main thread..

    simply paste the coding inside the following syntax

    dispatch_sync(dispatch_get_main_queue(), ^{
    
    //Your code goes here
    
    });
    

    or you can call your method using the following syntax

    [self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES]
    

    Hope this helps

    0 讨论(0)
  • 2020-12-10 01:52

    Durai answer in Swift 3:

    DispatchQueue.main.async {
      //Your code goes here
    }
    
    0 讨论(0)
  • 2020-12-10 02:03

    //The easiest way is to call the function using main thread for that.

    dispatch_async(dispatch_get_main_queue(), ^{ [self doSomething]; });

    0 讨论(0)
  • 2020-12-10 02:05
    This may be a result of calling to UIKit from a secondary thread. Crashing now...
    

    ...and as far as I can see that's just what you're doing. You're calling [alertProgress dismissWithClickedButtonIndex:0 animated:YES];, a UIKit method, from a thread other than your main thread(s), which is not allowed.

    For a very straight forward way to call back to the main thread if you can't use GCD, take a look at DDFoundation.

    Your code would in that case only change to do;

    [[alertProgress dd_invokeOnMainThread] dismissWithClickedButtonIndex:0 
                                           animated:YES]; 
    
    0 讨论(0)
提交回复
热议问题