diff --git a/js/ext/angular/test/service/ionicPlatform.unit.js b/js/ext/angular/test/service/ionicPlatform.unit.js index 25cf4cdf94a..7dd5b70814e 100644 --- a/js/ext/angular/test/service/ionicPlatform.unit.js +++ b/js/ext/angular/test/service/ionicPlatform.unit.js @@ -85,14 +85,14 @@ describe('Ionic Platform Service', function() { it('sets ios platforms', function() { window.cordova = {}; ionic.Platform.setPlatform('iOS'); - ionic.Platform.setVersion('7.9.3'); + ionic.Platform.setVersion('7.0.3'); ionic.Platform._checkPlatforms() expect(ionic.Platform.platforms[0]).toEqual('cordova'); expect(ionic.Platform.platforms[1]).toEqual('ios'); expect(ionic.Platform.platforms[2]).toEqual('ios7'); - expect(ionic.Platform.platforms[3]).toEqual('ios7_9'); + expect(ionic.Platform.platforms[3]).toEqual('ios7_0'); }); it('sets android platforms', function() { @@ -191,7 +191,7 @@ describe('Ionic Platform Service', function() { expect(ionic.Platform.is('android')).toEqual(false); }); - it('is android', function() { + it('is iOS', function() { ionic.Platform.setPlatform('iOs'); expect(ionic.Platform.is('ios')).toEqual(true); ionic.Platform.setPlatform('iOs'); @@ -202,4 +202,17 @@ describe('Ionic Platform Service', function() { expect(ionic.Platform.is('android')).toEqual(false); }); + it('should be all platforms for ios', function() { + window.cordova = {}; + ionic.Platform.setPlatform('iOS'); + ionic.Platform.setVersion('7.1.4'); + ionic.Platform._checkPlatforms(); + + expect(ionic.Platform.is('ios')).toEqual(true); + expect(ionic.Platform.is('ios7')).toEqual(true); + expect(ionic.Platform.is('ios7_1')).toEqual(true); + expect(ionic.Platform.is('cordova')).toEqual(true); + expect(ionic.Platform.is('android')).toEqual(false); + }); + }); diff --git a/js/utils/platform.js b/js/utils/platform.js index b7d6d964609..9806f05636e 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -42,7 +42,13 @@ _checkPlatforms: function(platforms) { this.platforms = []; this.grade = 'a'; - var v = this.version().toString().replace('.', '_'); + + var v = this.version().toString(); + if(v.indexOf('.') > 0) { + v = v.replace('.', '_'); + } else { + v += '_0'; + } if(this.isCordova()) { this.platforms.push('cordova'); @@ -107,12 +113,21 @@ // Check if the platform is the one detected by cordova is: function(type) { + type = type.toLowerCase(); + // check if it has an array of platforms + if(this.platforms) { + for(var x = 0; x < this.platforms.length; x++) { + if(this.platforms[x] === type) return true; + } + } + // exact match var pName = this.platform(); if(pName) { - return pName.toLowerCase() === type.toLowerCase(); + return pName.toLowerCase() === type; } - // A quick hack for - return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0; + + // A quick hack for to check userAgent + return navigator.userAgent.toLowerCase().indexOf(type) >= 0; }, exitApp: function() {