Ejecta icon indicating copy to clipboard operation
Ejecta copied to clipboard

userAgent

Open weepy opened this issue 13 years ago • 11 comments

Is it possible to know the iPhone / iPad version and iOS version in JS-Land?

weepy avatar Jul 30 '13 11:07 weepy

window.navigator.userAgent reports something like Ejecta/1.3 (iPhone; OS 7.0)

Detecting the hardware version (e.g. iPhone4 vs. iPhone4s) is difficult and Apple doesn't want you to be able to do it. You can however check for retina support with window.devicePixelRatio == 2 and detect iPhone5 with window.innerHeight == 568.

phoboslab avatar Jul 30 '13 11:07 phoboslab

Could we add the platform in as in this example http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk/3950748#3950748

weepy avatar Jul 31 '13 16:07 weepy

Frankly, this looks like a nightmare to maintain. So no, I don't want to add this. Maybe we could return the "raw" deviceModel, e.g. iPhone5,2, but I'm not too keen on that either.

phoboslab avatar Jul 31 '13 17:07 phoboslab

The raw device model is what I meant - it would be silly to do any thing else. I need to be able to turn certain features off on iPhone4 vs iPhone4S (due to clock speed)--- and I'm sure I'm not the only one. There's really no other sensible way. What's your issue ?

weepy avatar Jul 31 '13 17:07 weepy

You can already detect pre iPhone5 with window.innerHeight != 568.

I just don't want to maintain a huge list of device names (as in your SO link). Also, implementing even such a minuscule feature takes time. I'll probably do with my next Ejecta maintenance stretch. If you want it faster, send a pull request... or maybe I should register on Gittip already :)

phoboslab avatar Jul 31 '13 18:07 phoboslab

Oh - I wasn't suggesting that you should implement it. PR is obviously the way to go. Just wanted to check it was the right thing to do ^_^

On Wed, Jul 31, 2013 at 7:12 PM, Dominic Szablewski < [email protected]> wrote:

You can already detect pre iPhone5 with window.innerHeight != 568.

I just don't want to maintain a huge list of device names (as in your SO link). Also, implementing even such a minuscule feature takes time. I'll probably do with my next Ejecta maintenance stretch. If you want it faster, send a pull request... or maybe I should register on Gittip already :)

— Reply to this email directly or view it on GitHubhttps://github.com/phoboslab/Ejecta/issues/213#issuecomment-21883257 .

weepy avatar Jul 31 '13 19:07 weepy

@weepy You cannot distinguish between an iPhone 4 and 4s in userland; the models are too similar.

However, just hook the model in ObjC-land: NSString *model = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]. It will either yield iPhone3,1 on an iPhone 4 or iPhone4,1 on an iPhone 4s.

19h avatar Aug 01 '13 14:08 19h

Yep - so I was asking if it was a good idea to report that code as part of the useragent

On Thu, Aug 1, 2013 at 3:24 PM, Kenan Sulayman [email protected]:

@weepy https://github.com/weepy You cannot distinguish between an iPhone 4 and 4s in userland; the models are too similar.

However, just hook the model-version in ObjC-land: NSString *modelName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];. It will either yield iPhone3,1 on an iPhone 4 or iPhone4,1 on an iPhone 4s.

— Reply to this email directly or view it on GitHubhttps://github.com/phoboslab/Ejecta/issues/213#issuecomment-21939782 .

weepy avatar Aug 01 '13 14:08 weepy

True. This could be attached as window.navigator.model.

19h avatar Aug 01 '13 14:08 19h

What's the point of knowing the OS version? There would be more and more devices in the further. And you may want to run your game in other environments like browser, or android. I thought screen-size and devicePixelRatio detection would be enough.

aki-xavier avatar Aug 02 '13 01:08 aki-xavier

CPU speed etc

On Friday, August 2, 2013, Aki Xavier wrote:

What's the point of knowing the OS version? There would be more and more devices in the further. And you may want to run your game in other environments like browser, or android. I thought screen-size and devicePixelRatio detection would be enough.

— Reply to this email directly or view it on GitHubhttps://github.com/phoboslab/Ejecta/issues/213#issuecomment-21981123 .

weepy avatar Aug 02 '13 06:08 weepy