我创建了与 ios 7 和 ios 8 兼容的应用程序,但 ios 7 上的 UIWebview delegete 从未调用过,我得到了
void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
我在网上搜索,但没有解决方案 4 天尝试没有运气..
class AWTncViewController: UIViewController, UIWebViewDelegate{
@IBOutlet weak var wv: UIWebView!
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
wv.delegate = nil
}
override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
self.wv.delegate = self;
let myHTMLString:String! = "<h1>Hello word!</h1>"
self.wv.loadHTMLString(myHTMLString, baseURL: nil)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
/* Test 2 still not load
let myHTMLString:String! = "<h1>Hello word!</h1>"
self.wv.loadHTMLString(myHTMLString, baseURL: nil)
*/
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
//this never called
println("shouldStartLoadWithRequest execute")
return true
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool
{
//this never called
println("shouldStartLoadWithRequest execute")
return true
}
func webViewDidStartLoad(webView: UIWebView)
{
//this never called
println("Start load")
}
func webViewDidFinishLoad(webView: UIWebView)
{
//this never called
println("FinishLoad")
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError)
{
//this never called
println("didFailLoadWithError: \(error.description)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
我读到这个:iOS 7 UIWebView not rendering
但我没有使用 Crittercism
最佳答案
我也遇到了这个问题。问题似乎是链接某些第 3 方库时引起的,但我什至不确定在我的案例中到底是哪个库造成的。
为我解决问题的是我找到的建议 here on Apple's Dev Forum尽早实例化一个 UIWebView
。
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// In a severe case of WTF: some 3rd party libs (exact culprit unknown) can cause webviews to stop
// showing anything on iOS 7, and instead have console warnings every 10 seconds that look like:
// void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
// Just instantiating an UIWebView before any of the 3rd party libs kick in is enough to fix it.
// Don't know why, but it works.
if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
webView.delegate = nil; // Do something with webView to silence warning
}
return YES;
}
关于ios - swift void SendDelegateMessage.. webView :decidePolicyForNavigationActionfailed to return after waiting 10 seconds. .. kCFRunLoopDefaultMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32661910/