Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.

fix detect ipad issues#1104 #1110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/platform/platform-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@ export function isCordova(plt: Platform): boolean {
export function isElectron(plt: Platform): boolean {
return plt.testUserAgent('Electron');
}
export function isIpad(plt: Platform): boolean {
// iOS 12 and below
if (testUserAgent(plt.win(), /iPad/i)) {
return true;
}

// iOS 13+
if (testUserAgent(plt.win(), /Macintosh/i) && isMobile(plt.win())) {
return true;
}

return false;
}

export function isIphone(plt: Platform): boolean {
return testUserAgent(plt.win(), /iPhone/i);
}

export function isIos(plt: Platform): boolean {
// shortcut function to be reused internally
// checks navigator.platform to see if it's an actual iOS device
// this does not use the user-agent string because it is often spoofed
// an actual iPad will return true, a chrome dev tools iPad will return false
return plt.testNavigatorPlatform('iphone|ipad|ipod');
return testUserAgent(plt.win(), /iPhone|iPod/i) || isIpad(plt);
}

const isMobile = (win: Window) => matchMedia(win, '(any-pointer:coarse)');

export function isSafari(plt: Platform): boolean {
return plt.testUserAgent('Safari');
}
Expand All @@ -31,3 +46,11 @@ export function isIosUIWebView(plt: Platform): boolean {
return isIos(plt) && !isWKWebView(plt) && !isSafari(plt);
}


export function testUserAgent(win: Window, expr: RegExp): boolean {
return expr.test(win.navigator.userAgent);
}

export function matchMedia(win: Window, query: string): boolean {
return win.matchMedia(query).matches;
}