Check platform type

I want to check if a session runs on mobile or desktop.
This code below is copied from the xojo documentation.

select case self.Platform

case WebSession.PlatformType.desktop
LoginDesktop.show

case else

end select

When I compile I get the error: This item does not exist. (WebSession.PlatformType.deskTop)
What’s wrong?

I think that code is for Web 1, so if you are using Xojo2020 or later, that code will not work.

Found this thread:

Can you share the link to the documentation? Maybe there is a documentation bug that needs to be fixed.

2 Likes

This is some code @Alvaro_Fontan and I wrote, during the Xojo Developer Retreat:

Try
  Var rx As New RegEx
  rx.SearchPattern = "android|iphone|kindle|ipad"
  rx.Options.CaseSensitive = False
  
  Var userAgent As String = Session.Header("User-Agent")
  Var match As RegExMatch = rx.Search(userAgent)
  Return match <> Nil And match.SubExpressionCount > 0
Catch e As RegExException
  Return False
End Try

But as @Greg_O said in the other thread, maybe you just need to detect the screen size, using WebSession.ClientWidth and WebSession.ClientHeight.

http://man.hubwiz.com/docset/Xojo.docset/Contents/Resources/Documents/docs.xojo.com/UserGuide_Web_Mobile_Support.html

I solved the issue with checking self.clientHeight and self.clientWidth.
Thank you, but we can’t rely on the documentation. I just posted another issue with downloading files.

That is not the official/current documentation but a snapshot of old docs, you should use https://documentation.xojo.com