Skip to content

Instantly share code, notes, and snippets.

@mlabieniec
Created October 28, 2018 16:28
Show Gist options
  • Save mlabieniec/18e0b785a22fb5364cbc0b3b3135d9f5 to your computer and use it in GitHub Desktop.
Save mlabieniec/18e0b785a22fb5364cbc0b3b3135d9f5 to your computer and use it in GitHub Desktop.
PWA iOS Detection and Installation Banner
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