Created
October 28, 2018 16:28
-
-
Save mlabieniec/18e0b785a22fb5364cbc0b3b3135d9f5 to your computer and use it in GitHub Desktop.
PWA iOS Detection and Installation Banner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
// Detects if device is on iOS | |
const isIos = () => { | |
const userAgent = window.navigator.userAgent.toLowerCase(); | |
return /iphone|ipad|ipod/.test( userAgent ); | |
} | |
// Detects if device is in standalone mode | |
const isInStandaloneMode = () => ('standalone' in (window as any).navigator) && ((window as any).navigator.standalone); | |
// Checks if should display install popup notification: | |
if (isIos() && !isInStandaloneMode()) { | |
this.toast.openFromComponent(IosInstallComponent, { | |
duration: 8000, | |
horizontalPosition: 'start', | |
panelClass: ['mat-elevation-z3'] | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment