0

I am trying to detect if a user is using an Apple device, this is because I am trying to integrate Apple pay on my software, and I don't want to show android users Apple pay option. They say using USER agent can be used but can also be spoofed, is there a more secure method.

I saw this answer

Detecting iOS / Android Operating system . I dont want just iOS device as iOS doesnt run on Macbook

AND

Detect Apple Device Model . But it is on Objective C

AND

Detect if user is using an iDevice . It did not answer the question.

Shasha
  • 439
  • 8
  • 26

1 Answers1

1

From Apple’s website:

if (window.ApplePaySession) {
   // The Apple Pay JS API is available.
}

After doing that you can also detect if they have a at least one card provisioned using canMakePaymentsWithActiveCard

Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • Hi chris thanks for your answer, but I want to detect if it is an apple device before this, your answer is highly appreciated, upvotted – Shasha Mar 21 '22 at 11:58
  • 1
    This is the best and really only reliable way. What more would you want? If this is falsey, you know to not bother, but otherwise you have a supported device. I don't think you should care about spoofed UA's, that's an edge case where someone is only hurting themselves, not you. But UA parsing in general is fragile so I'd always avoid it. The test posted here works on every browser, even IE6 (probably) wouldn't freak out on it. – Chris Haas Mar 21 '22 at 13:34