Skip to content

Commit

Permalink
fix(platform): detect iPad Pro correctly (#10292)
Browse files Browse the repository at this point in the history
* fix(platform): iPad pro is detected as an iPad

* chore(platform): ipad should be last
  • Loading branch information
jgw96 authored and brandyscarney committed Feb 2, 2017
1 parent 7f304ed commit f12fc61
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,16 @@ export class Platform {
while (platformNode) {
platformNode.initialize(this);

// extra check for ipad pro issue
// https://forums.developer.apple.com/thread/25948
if (platformNode.name === 'iphone' && this.navigatorPlatform() === 'iPad') {
// this is an ipad pro so push ipad and tablet to platforms
// and then return as we are done
this._platforms.push('tablet');
this._platforms.push('ipad');
return;
}

// set the array of active platforms with
// the last one in the array the most important
this._platforms.push(platformNode.name);
Expand Down
31 changes: 31 additions & 0 deletions src/platform/test/platform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,37 @@ describe('Platform', () => {
expect(plt.is('tablet')).toEqual(true);
});

// for https://forums.developer.apple.com/thread/25948
it('should set ipad when user agent is iphone but navigator.platform is iPad', () => {
plt.setQueryParams('');
plt.setUserAgent(IPHONE_UA);
plt.setNavigatorPlatform('iPad');
plt.init();

expect(plt.is('core')).toEqual(false);
expect(plt.is('mobile')).toEqual(true);
expect(plt.is('windows')).toEqual(false);
expect(plt.is('android')).toEqual(false);
expect(plt.is('ios')).toEqual(true);
expect(plt.is('ipad')).toEqual(true);
expect(plt.is('iphone')).toEqual(false);
expect(plt.is('tablet')).toEqual(true);

plt.setQueryParams('');
plt.setUserAgent(IPHONE_10_2_UA);
plt.setNavigatorPlatform('iPad');
plt.init();

expect(plt.is('core')).toEqual(false);
expect(plt.is('mobile')).toEqual(true);
expect(plt.is('windows')).toEqual(false);
expect(plt.is('android')).toEqual(false);
expect(plt.is('ios')).toEqual(true);
expect(plt.is('ipad')).toEqual(true);
expect(plt.is('iphone')).toEqual(false);
expect(plt.is('tablet')).toEqual(true);
});

it('should set core platform for osx desktop firefox', () => {
plt.setQueryParams('');
plt.setDefault('core');
Expand Down

0 comments on commit f12fc61

Please sign in to comment.