Sunday, March 3, 2013

UIWebView thread issue

When using ios UIWebView control, few thread related issues need to be kept in mind to avoid errors.
1. executeJavaScriptWithReturnValueInternal can only be caused from main thread, and it will block the main thread
2. If the caller of executeJavaScriptWithReturnValueInternalis already in main thread, like the call is triggered by a button click, (ios ui event is handled in main thread), then it can be called directly. If the caller is in background thread, the method needs to be called by performSelectorOnMainThread to switch to main thread.
3. Although uiWebView is single threaded, it can send multiple async xmlhttpRequests, including the cachedResponseForRequest

No comments:

Post a Comment