-
-
Save IgorMinar/863acd413e3925bf282c to your computer and use it in GitHub Desktop.
/** | |
* ================== 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; | |
} | |
}]); | |
}]); |
WOrks perfect. thanks 👍
Did anyone tried this patch with Cordova-ios 4.0.1? On Cordova-ios 3.9.2, this patch works perfectly but if I update to 4.0.1, I still run into an infinite loop when Angular starts. Using ionic 1.1.1 or 1.2.1 does not make any difference. Thanks
@hammady. Thank you for reminding about this. Solved my case!
Do we need to apply this change if we use ionic 1.2.0?
@mathieugerard same here...
@dorshay6, @edmondchui: It's already included in 1.2.0.
@IgorMinar: Iam using ionic framework, I found the problem with css "overflow" attribute (using bootstrap class "table-responsive"), at android it's working fine, but at ios9 can't scroll horizontal.
Does this patch apply to WKWebView?
Does any one have a clue if similar patch is needed for ios 10?
@mihneasim: I found the same issue in ionic app when using com.passslot.cordova.plugin.passbook when testing on ios 10. After invoking the pass screen and clicking on add, navigating away from the app screen that caused the invoke was causing 10 $digest() iterations reached. For now, I have locally added the ios 10 check to the patch for my project and things are working fine.
This didn't solve my problem. My app works fine in android and ios10, but doesn't work nice in some cases in ios9.
I used this patch but still have this issue with Ionic 1.3.2.
thanks a lot ... its works for me..