ios - swift void SendDelegateMessage.. webView :decidePolicyForNavigationActionfailed to return after waiting 10 seconds. .. kCFRunLoopDefaultMode

标签 ios swift uiwebview xcode6

我创建了与 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/

相关文章:

ios - IBAction 函数已正确连接但未执行

ios - 裁剪图像中心

ios - Swift 3.0 (iOS) 中用于密码散列的 Scrypt 散列算法

swift - 使用 Alamofire 发布并解析响应 | swift 5

iphone - 3 UIScrollview 上的 UIWebView 在浏览时崩溃

c# - MonoTouch File.ReadAllText 在内部 FileStream.Dispose() 上抛出异常

ios - 在多次删除行时删除 UITableView 上的行中的错误

ios - 当关系从多变为一时如何执行迁移?

ios - 为 UIWebView 中的 contenteditable div 禁用自动大写

iphone - 从嵌套文件夹结构加载带有本地 HTML 文件的 UIWebview