AhsanAyaz / ngx-device-detector

An Angular v7+ library to detect the device, OS, and browser details.
https://ahsanayaz.github.io/ngx-device-detector
MIT License
521 stars 101 forks source link

device detector is flagging ipad and iphone devices as desktop #228

Open omio-ma opened 3 years ago

omio-ma commented 3 years ago

Describe the bug After upgrading to the latest version we have identified that the isDesktop function is returning true for iphone and ipad devices. We have also noticed the same result when trying out this app: https://koderlabs.github.io/ngx-device-detector/demo/

We have attached screenshots of what it returns.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'https://koderlabs.github.io/ngx-device-detector/demo/'
  2. Click on 'N/A.'
  3. Scroll down to 'isDesktop'
  4. isDesktop is returning true for iphone and iPad

Expected behavior From what I understand (do correct me if I am wrong), the isDesktop function should return false for iphone/ipad devices which appeared to be the case in the earlier version we have used (which was 2.0.5). I was wondering if this commit might have caused this issue perhaps: https://github.com/KoderLabs/ngx-device-detector/commit/cea0f9edcfc77620b3b8621af23cfbf39811f645?

Screenshots ipad: Image from iOS

iphone: File

Ipad (please complete the following information):

Ipad (please complete the following information):

Smartphone (please complete the following information):

rmeske commented 2 years ago

This is the problem relying on the user agent. Apple made a decision to change iPadOS to report as macOS. Their reasoning is they wanted their users to have a universal experience regardless of the device being used to view a web page. Their argument is that html pages should be designed to be responsive to the screen size not the device. I have no doubt that at some point in the future iOS will also report as macOS.

As a developer, I understand there are times you do need to know which device is being used. What I rely on now are "deviceType", "isDesktop", "isTablet", and "isMobile". I always check "isTablet" first, then "isMobile" just in case a tablet also reports isMobile as true, and finally I check isDesktop.

Rybadour commented 2 years ago

My team just tested this on IPhone 13, IOS 15.3.1, Safari and it seems to have been fixed.

deviceType = mobile isDesktop() = false isTablet() = false isMobile() = true

empro-narendervaddepelly commented 6 months ago

This is still an issue. any fair solutions?

purplefrizzel commented 1 month ago

Anyone looking for a solution, this seems to work:

import { inject, Injectable } from '@angular/core';
import { DeviceDetectorService } from 'ngx-device-detector';

@Injectable({
    providedIn: 'root',
})
export class MyServiceName {
    private readonly _deviceDetectorService: DeviceDetectorService = inject(DeviceDetectorService);

    public isMobile(): boolean {
        return this._deviceDetectorService.isMobile();
    }

    public isTablet(): boolean {
        return this._deviceDetectorService.isTablet() && !this.isMobile();
    }

    public isDesktop(): boolean {
        return this._deviceDetectorService.isDesktop() && !this.isTablet();
    }
}

Tested on a year old iPad running iPadOS 18

P.S. It might be worth updating this lib to take the iPad issues into account because Apple will not move on this issue.