How do I detect if it's iphone or ipad ?

Get help using Construct 2

Post » Sat Jan 21, 2017 9:53 pm

Hi,
is there a way to detect if the device is an iphone or ipad please ?
thanks for help
B
44
S
16
G
8
Posts: 791
Reputation: 8,279

Post » Sun Jan 22, 2017 9:25 am

Some conditions that could help:
(Compare two values)
Browser.ExecJS("navigator.platform.toLowerCase().indexOf('iphone') > -1") Not Equal To 0
Browser.ExecJS("navigator.platform.toLowerCase().indexOf('ipod') > -1") Not Equal To 0
Browser.ExecJS("navigator.platform.toLowerCase().indexOf('ipad') > -1") Not Equal To 0
Browser.ExecJS("navigator.platform.toLowerCase().indexOf('mac') > -1") Not Equal To 0
Browser.ExecJS("navigator.vendor.toLowerCase().indexOf('apple') > -1") Not Equal To 0

I used all the conditions together in OR condition to determine if I'm in iOS device, woked for me like a charm.
But for your need it should also work independently to determine exact device.
B
60
S
31
G
6
Posts: 124
Reputation: 7,856

Post » Sun Jan 22, 2017 3:13 pm

@Yura G
thanks a lot
so if i want to do something on ipad specially ... i have to use the condition "Browser.ExecJS("navigator.platform.toLowerCase().indexOf('ipad') > -1") Not Equal To 0" right ?
B
44
S
16
G
8
Posts: 791
Reputation: 8,279

Post » Sun Jan 22, 2017 4:07 pm

@matrixreal
Right,
but that navigator trick sometimes may give false positives and false negatives.
It never accured to me, and no one complained, but I heard that it can happen, depending on device and browser.
Just saying, in my opinion it is 99% safe to use.
B
60
S
31
G
6
Posts: 124
Reputation: 7,856

Post » Mon Jan 23, 2017 7:39 pm

Could this type of action be used to determinate not only what device is being used but also the screen resolution? (16:9, 16:10, 4:3 and so on?)

I think this could be really usefull to maybe find a way to adapt the view of your game to the user´s screen resolution and achieve a perfect display in almost all devices.
B
26
S
14
G
8
Posts: 49
Reputation: 6,250


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests