zoukankan      html  css  js  c++  java
  • ios9下ionic框架报[$rootScope:infdig] 10 $digest() iterations reached. Aborting!的解决办法

    升级ios9后,ionic开发的app会报[$rootScope:infdig] 10 $digest() iterations reached. Aborting!的错误,加上一个patch就可以解决

    在index.html里引入js
    <script type="text/javascript" src="js/angular-ios9-uiwebview.patch.js"></script>

    app.js里加入dependency 'ngIOS9UIWebViewPatch'
    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngIOS9UIWebViewPatch'])

    js/angular-ios9-uiwebview.patch.js的下载地址:
    https://gist.github.com/IgorMinar/863acd413e3925bf282c

    -----------------------------------------------------------------------------------------------
    作者blog:
    http://blog.ionic.io/ios-9-potential-breaking-change/
    作者blog全文:

    Update (9/11/2015): A new version of the patch was released by Igor on the Angular team that fixes many issues. Please use it: angular-ios9-uiwebview.patch.js. Make sure to add 'ngIOS9UIWebViewPatch' to your angular modules and use version 1.1.0 or higher of the patch. Also, see our latest postabout other issues that need addressing.

    A breaking change was introduced into UIWebView for iOS 9 that could cause issues for apps that heavily rely on the semantics of window.location.

    We’ve tested a number of widely-used Ionic apps with iOS 9 beta and GM, and issues appear to be isolated to intermittent UI/navigation issues on some apps, along with console errors indicating infinite digest warnings in Angular. Functionality beyond that should not be impacted.

    We are still investigating the impact of this change and working with the Angular team to develop a long-term fix. In the meantime, we’ve (the Angular team has) created a patch to stop the digest issue which was causing the console errors. This hot fix can be included in the majority of Ionic and Angular apps (even those running alpha/beta/rc) releases. If you rely on the semantics of window.location or use the $location service heavily, and have noticed issues on iOS 9 GM please try the patch and let us know how it works for you.

    If you do notice an issue with your app in iOS 9, add the patch, and submit your apps for review. There is an openradar issue for this that you might be able to reference to expedite an update (of course, no guarantees). There is supposedly a fix in the works from Apple, but it wasn’t released in time for GM.

    Thanks to everyone that has helped us with this issue. If this issue has caused an issue in your app, please let us know (and we are sincerely sorry) as we work towards a permanent fix.


    ---------------------------------------------------------------------------------------------
    ---js/angular-ios9-uiwebview.patch.js----------------------------------------------------------------------

    /**
    * ================== angular-ios9-uiwebview.patch.js v1.1.1 ==================
    *
    * This patch works around iOS9 UIWebView regression that causes infinite digest
    * errors in Angular.
    *
    * The patch can be applied to Angular 1.2.0 – 1.4.5. Newer versions of Angular
    * have the workaround baked in.
    *
    * To apply this patch load/bundle this file with your application and add a
    * dependency on the "ngIOS9UIWebViewPatch" module to your main app module.
    *
    * For example:
    *
    * ```
    * angular.module('myApp', ['ngRoute'])`
    * ```
    *
    * becomes
    *
    * ```
    * angular.module('myApp', ['ngRoute', 'ngIOS9UIWebViewPatch'])
    * ```
    *
    *
    * More info:
    * - https://openradar.appspot.com/22186109
    * - https://github.com/angular/angular.js/issues/12241
    * - https://github.com/driftyco/ionic/issues/4082
    *
    *
    * @license AngularJS
    * (c) 2010-2015 Google, Inc. http://angularjs.org
    * License: MIT
    */

    angular.module('ngIOS9UIWebViewPatch', ['ng']).config(['$provide', function($provide) {
    'use strict';

    $provide.decorator('$browser', ['$delegate', '$window', function($delegate, $window) {

    if (isIOS9UIWebView($window.navigator.userAgent)) {
    return applyIOS9Shim($delegate);
    }

    return $delegate;

    function isIOS9UIWebView(userAgent) {
    return /(iPhone|iPad|iPod).* OS 9_d/.test(userAgent) && !/Version/9./.test(userAgent);
    }

    function applyIOS9Shim(browser) {
    var pendingLocationUrl = null;
    var originalUrlFn= browser.url;

    browser.url = function() {
    if (arguments.length) {
    pendingLocationUrl = arguments[0];
    return originalUrlFn.apply(browser, arguments);
    }

    return pendingLocationUrl || originalUrlFn.apply(browser, arguments);
    };

    window.addEventListener('popstate', clearPendingLocationUrl, false);
    window.addEventListener('hashchange', clearPendingLocationUrl, false);

    function clearPendingLocationUrl() {
    pendingLocationUrl = null;
    }

    return browser;
    }
    }]);
    }]);

  • 相关阅读:
    java exception
    【洛谷P1627】 【CQOI2009】中位数
    切蛋糕
    【NOIP2015Day2T2】【洛谷P2679】子串
    【NOIP2017Day1T3】【洛谷P3953】逛公园
    【bzoj1082】【SCOI2005】栅栏
    搬砖
    花花的森林
    跳跳棋
    异或
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/4834870.html
Copyright © 2011-2022 走看看