detect iphone or smartphone

I tried this (Page Not Found — Xojo documentation) and that
but both failed and i don’t know what i do wrong.
Using my iphone 6s plus and i got “Macintosh”, instead of iPhone… The secong gives “Unknown”!
Anyway to compare width and height screen size and use it instead of platformtype ?

Select Case Session.Platform Case WebSession.PlatformType.AndroidPhone MsgBox("AndroidPhone") Case WebSession.PlatformType.AndroidTablet MsgBox("AndroidTablet") Case WebSession.PlatformType.iPhone MsgBox("iPhone") Case WebSession.PlatformType.Macintosh MsgBox("Macintosh") Case WebSession.PlatformType.Windows MsgBox("Windows") Case WebSession.PlatformType.Unknown MsgBox("Unknown platform type") End Select

Dim p As WebSession.PlatformType = session.Platform If p = WebSession.PlatformType.AndroidPhone Or p = WebSession.PlatformType.iPhone Then msgbox("Mobile enable") End If

I did a test, a webapp with only a label. In the label open event I put you Select Case code and it works, for my mac it say Macintosh and for my phone it say AndroidPhone.

Note: first I changed MsgBox to Me.Text, and the label shown the correct information. Then run it as is, and it shows the correct MsgBox. Don’t have an iPhone right now, but I could test later.

But using an iPhone, this is exactly the problem, I got MAcintosh insteadof iPhone.
I use Windows7 Chrome Xojo2018.2

[quote=407423:@Michael Batakis]But using an iPhone, this is exactly the problem, I got MAcintosh insteadof iPhone.
I use Windows7 Chrome Xojo2018.2[/quote]
The problem is that the web framework currently uses user-agent parsing to figure out what the device is. If Apple has changed that string drastically (and they do from time to time) it should be that they’re no longer indicating that it’s an iOS device.

Ok, I just checked this on

https://www.whatismybrowser.com

And the user agent strings for mobile Safari have not changed enough to cause this issue.

If you go to that page on the device that’s giving you trouble, scroll down to the section that says YOUR WEB BROWSER’S USER AGENT: and paste the value here.

Sorry for the late response, I was able to test on an iPhone 6 and the label/message show “iPhone”

Visited whatismybrowser and it say “Safari 11 on iOS 11.4”, part of the user agent show “…CPU iPhone OS 11_4_1 like Mac OS X…”

Maybe Michael is using different iOS version, not using the default browser with/or a changed user-agent?

I lost all yesterday’s evening try to find why… :-o

Safari:
Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1

Chrome
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12

just show that there is an update on Chrome… downloading

At the moment I’m interested to detect smallscreens, so if anyoneg ive me how to get user’s screen width/height i will be ableto tackle effectively.

I guess Safari will show as iPhone and Chrome will show as Macintosh, right?

I’m sorry I can’t help you more. I think the browser does not send the screen resolution so you may need to execute some javascript to get your visitor’s browser resolution: https://www.w3schools.com/jsref/prop_screen_width.asp

Cheers , Alberto
Could you please how to execute the javascript code and where to put in? I have tried to run javascript ehitin Xojo…

Sorry Michael, haven’t learned that yet.

I searched for xojo web javascript and got this, hope you can make it work:
https://documentation.xojo.com/index.php/WebControl.ExecuteJavaScript
https://forum.xojo.com/8058-how-to-get-a-javascript-value/0
https://forum.xojo.com/41486-where-to-execute-javascript/0
https://forum.xojo.com/31547-execute-simple-javascript/0
https://forum.xojo.com/15713-how-to-use-javascript/0

Edit: if you want to know the browser size you can use .width. This is from other thread:

Cheers!

Yes. If the browser doesn’t tell us what the device is (or lies to us) there’s not much we can do about it.

Anyway I manage to solve it:if I got Macintosh and Self.height>Self.Width then it is an iPhone!

However, I tried the Javascript things. As I was looking in related posts, there is a bit tricky of how to get a returned value. Is it so difficult Xojo to implement using Xojo.Trigger.Event a function to get easily a returned javascript value? I’m just curious, as I think that it is highly important the user to be able to use Javascript in a proper way and get easily the return value…

I m thinking like that:
Using DOM’s , could a user use a Javascript to set it with the returned Javascript value and then using xojo to read the WebPage.HelpTag (or another’s control) so to get the returned Javascript value and use it accordingly? Or like something that, if you get what i mean (don’t be familiar with them . just a thought)

[quote=407943:@Michael Batakis]I m thinking like that:
Using DOM’s , could a user use a Javascript to set it with the returned Javascript value and then using xojo to read the WebPage.HelpTag (or another’s control) so to get the returned Javascript value and use it accordingly? Or like something that, if you get what i mean (don’t be familiar with them . just a thought)[/quote]
You might as well use the WebSDK. It’s set up to let you do communications like that.

Could you please be more specific by telling me for what “word” to look in WebSDK?
Not very familiar with…

The WebSDK Documentation can be found in Xojo/Extras/WebSDK/ - you must be familiar with HTML/Javascript to understand it.
You may find a tool I made of some use, it creates empty WCW classes with a bunch of the basics filled in: http://webgen.timi.me

Thanks Tim, I can understand the code but I mentioned the above, just wondering why Xojo have not implemented an internal command to get returned Javascript values easily… It is supposed that most users of Xojo are not familiar with javascript and Html (otherwise they could make an app using only javascript and html having more flexibility in their projects).
Never mind…
Thank you again

PS: I have bought the “I Wish I Knew How To… Program HTML, CSS, and JavaScript with Xojo”… very useful!

1 Like