Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* ================== 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;
}
}]);
}]);
@chabislav
Copy link

chabislav commented Nov 6, 2015

@IgorMinar, Thanks a lot brother.

@HarryWang74
Copy link

HarryWang74 commented Nov 6, 2015

thanks a lot.

@leopiazzoli
Copy link

leopiazzoli commented Nov 9, 2015

Thanks man.

@PedroJusto
Copy link

PedroJusto commented Nov 9, 2015

@pcrombach did you solve the problem? I have exactly the same problem!!

@tekolie
Copy link

tekolie commented Nov 10, 2015

Thanks a lot!

@lvbeck
Copy link

lvbeck commented Nov 11, 2015

thanks

@johntomcy
Copy link

johntomcy commented Nov 11, 2015

@kapil019 Ionic tip: to prevent flashes of a black background, make sure you set ion-nav-view's background-color to transparent.

https://github.com/Telerik-Verified-Plugins/WKWebView

@ddbaron
Copy link

ddbaron commented Nov 14, 2015

Bug fixed in Ionic v1.1.1 -> you don't need this patch any more as it is addressed in ios9 location patch ionic-team/ionic-framework@e5b85df

@swren
Copy link

swren commented Nov 17, 2015

Thank you!! this fixed the issue for my App immediately.

I was getting multiple "[$rootScope:infdig] 10 $digest() iterations reached" errors

Cheers

@asemoon
Copy link

asemoon commented Nov 17, 2015

@ddbaron I am running latest version of ionic , however, I am getting "10 $digest() iterations reached" message upon using $state.go. It only happens when I run the app on the device and it seems to be ok when using ionic serve.

@boyfunky
Copy link

boyfunky commented Nov 27, 2015

I'm having a weird issue on iOS whereby i have a form the ppl hv to input their phone numbers nd it saves and displays the number in another page.

I save first number 0123456789 it saves and displays correctly but when i save another number, it attaches the previous number to the new number although in my db it doesn't save both as one number. but somehow this number is cached on my view page nd shows. everything other field shows correctly but only the number field.

Happens only on iOS not on Android

@sonukapoor
Copy link

sonukapoor commented Nov 30, 2015

This patch works fine for AngularJS v1.3.13 as well. Thanks to the Author!

@gabrielkaputa
Copy link

gabrielkaputa commented Dec 3, 2015

Thank you!!!!

@renanss
Copy link

renanss commented Dec 4, 2015

Some heroes doesn't need a cape. They are coder heroes.
You saved our day, thank you so much!

@kettula
Copy link

kettula commented Dec 9, 2015

Beautiful. Thank you!

@edsykes
Copy link

edsykes commented Dec 15, 2015

updating to the latest version of ionic ( 1.1.1 ) also fixes the issue that this patch addresses

@srthakkar
Copy link

srthakkar commented Dec 18, 2015

thanks a lot ... its works for me..

@sahotataran
Copy link

sahotataran commented Dec 18, 2015

WOrks perfect. thanks 👍

@mathieugerard
Copy link

mathieugerard commented Dec 29, 2015

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

@rsanteri
Copy link

rsanteri commented Jan 7, 2016

@hammady. Thank you for reminding about this. Solved my case!

@edmondchui
Copy link

edmondchui commented Jan 8, 2016

Do we need to apply this change if we use ionic 1.2.0?

@dorshay6
Copy link

dorshay6 commented Feb 18, 2016

@mathieugerard same here...

@andriasang
Copy link

andriasang commented Feb 29, 2016

@dorshay6, @edmondchui: It's already included in 1.2.0.

@WhiteFangWBC
Copy link

WhiteFangWBC commented Mar 15, 2016

@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.

@jpike88
Copy link

jpike88 commented Mar 25, 2016

Does this patch apply to WKWebView?

@mihneasim
Copy link

mihneasim commented Oct 15, 2016

Does any one have a clue if similar patch is needed for ios 10?

@ajnrajeev
Copy link

ajnrajeev commented Oct 19, 2016

@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.

@vahidvdn
Copy link

vahidvdn commented Nov 2, 2016

This didn't solve my problem. My app works fine in android and ios10, but doesn't work nice in some cases in ios9.

@vineelasanu
Copy link

vineelasanu commented Feb 8, 2017

Helo I did one hybrid app that was properly working in android, but in iOS its working but getting problem at booking time slots are not working any ideas. here is my screenshot.
screen shot 2017-02-06 at 5 43 09 pm
Thanks in advance.

@tuanbs
Copy link

tuanbs commented Mar 17, 2017

I used this patch but still have this issue with Ionic 1.3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment