Skip to content

Commit f12fc61

Browse files
jgw96brandyscarney
authored andcommitted
fix(platform): detect iPad Pro correctly (#10292)
* fix(platform): iPad pro is detected as an iPad * chore(platform): ipad should be last
1 parent 7f304ed commit f12fc61

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/platform/platform.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,16 @@ export class Platform {
986986
while (platformNode) {
987987
platformNode.initialize(this);
988988

989+
// extra check for ipad pro issue
990+
// https://forums.developer.apple.com/thread/25948
991+
if (platformNode.name === 'iphone' && this.navigatorPlatform() === 'iPad') {
992+
// this is an ipad pro so push ipad and tablet to platforms
993+
// and then return as we are done
994+
this._platforms.push('tablet');
995+
this._platforms.push('ipad');
996+
return;
997+
}
998+
989999
// set the array of active platforms with
9901000
// the last one in the array the most important
9911001
this._platforms.push(platformNode.name);

src/platform/test/platform.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,37 @@ describe('Platform', () => {
363363
expect(plt.is('tablet')).toEqual(true);
364364
});
365365

366+
// for https://forums.developer.apple.com/thread/25948
367+
it('should set ipad when user agent is iphone but navigator.platform is iPad', () => {
368+
plt.setQueryParams('');
369+
plt.setUserAgent(IPHONE_UA);
370+
plt.setNavigatorPlatform('iPad');
371+
plt.init();
372+
373+
expect(plt.is('core')).toEqual(false);
374+
expect(plt.is('mobile')).toEqual(true);
375+
expect(plt.is('windows')).toEqual(false);
376+
expect(plt.is('android')).toEqual(false);
377+
expect(plt.is('ios')).toEqual(true);
378+
expect(plt.is('ipad')).toEqual(true);
379+
expect(plt.is('iphone')).toEqual(false);
380+
expect(plt.is('tablet')).toEqual(true);
381+
382+
plt.setQueryParams('');
383+
plt.setUserAgent(IPHONE_10_2_UA);
384+
plt.setNavigatorPlatform('iPad');
385+
plt.init();
386+
387+
expect(plt.is('core')).toEqual(false);
388+
expect(plt.is('mobile')).toEqual(true);
389+
expect(plt.is('windows')).toEqual(false);
390+
expect(plt.is('android')).toEqual(false);
391+
expect(plt.is('ios')).toEqual(true);
392+
expect(plt.is('ipad')).toEqual(true);
393+
expect(plt.is('iphone')).toEqual(false);
394+
expect(plt.is('tablet')).toEqual(true);
395+
});
396+
366397
it('should set core platform for osx desktop firefox', () => {
367398
plt.setQueryParams('');
368399
plt.setDefault('core');

0 commit comments

Comments
 (0)