Cordova / PhoneGap iOS 8 Beta

iOS 8 Beta and Cordova <= 3.5.0

If you’ve had a play around with iOS 8 beta (like me), you’ll probably have noticed there’s an issue.

Cordova / PhoneGap iOS 8

WebKit iOS 8

If you take a look at the WebKit iOS 8 release notes you’ll see it makes specific mention of Cordova / PhoneGap:

Applications that use Apache Cordova / PhoneGap are broken due to a bug that causes the window.navigator.userAgent object to become undefined when window.navigator is replaced by a pure JavaScript wrapper object.

Essentially, what happens is Cordova / PhoneGap replaces the window.navigator, as you can see here.

The solution

Although this will be fixed in Cordova 3.6.0 when support for the new Cordova bridge under iOS 8 WKWebView is implemented, Eddy Verbruggen has come up with a neat little fix to check if the navigator.userAgent is undefined and assign a return value to it:

if (navigator.userAgent === undefined) {
navigator.__defineGetter__('userAgent', function() {
return("Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit");

Also, targeting 7.0 (which I doubt you’re doing if you’re playing with iOS 8 beta) should also still work.