Iphone Web Thread _WebThreadLockFromAnyThread

送分小仙女□ 提交于 2019-12-22 04:43:34

问题


Perhaps one Iphone Guru can enlighten me...

I've been going line-by-line and eliminating any threads calls / NSInvocation's that use the UIKit, as a matter of fact, I have made 100% sure that NO UIKit crap gets called from any-where else except the MainThread I.E...

if([NSThread isMainThread])
{
  blah....
  Call UIKit Crap here!
  and blah....
}

So far so good, but then after I created a thread to do a http POST (using LibCurl) I started getting this:

"void _WebThreadLockFromAnyThread(bool), 0x4d7bbe0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread."

Like WTF...? I can't even Use Curl from a Thread, to do a Network Intensive Operation..? I just moved this damn thing, off the mainThread, to Comply with Their (Apple's) UIKit's strict, "Don't call any UIKit crap, except from the Main Thread...PERIOD or Else!!!"

So I move the "UiAlertView & UIActivityIndicator" back onto the main thread (No error messages before) and create a thread to do the curl POST operation... Now that I am in compliance, and then all of a sudden, I start getting this message...?

Can anyone explain where I am suppose to put this Network intensive operation, which, by the way, will cause the any UIActivity Indicator's / UIAlertView's to freeze in their tracks...

Thanks in Advance...

[I am just a linux programmer in sheep's clothing]


回答1:


Ok, The answer (Has nothing at all to do with Curl or some fictional notification to the main thread)

Anyone who gets this error, Don't think WEB Thread or Main Thread, THINK, UITextView or UIScrollView or any other view that might be getting passed off to your new thread.

My problem was a UITextView.text, that was being passed as an argument to the NEW thread... Hence "_WebThreadLockFromAnyThread(bool)"

So a simple fix was to copy it to a local NSString and pass that copy in the argument, to the new thread (I.E... Warning: UIKit should not be called from a secondary thread)

[NSThread detachNewThreadSelector: @selector(sendStuff:) toTarget: self withObject: self.textField.text];

When you see hoof prints, THINK horses, NOT Zebra's.



来源:https://stackoverflow.com/questions/6289309/iphone-web-thread-webthreadlockfromanythread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!