1 2 Previous Next 22 Replies Latest reply on Dec 22, 2015 1:32 PM by disabled_JackRodgers

    Script for Detecting iPhone or iPad?

    joshw

      I've been trying to build a script that will detect when a user logs in on a iPad or a iPhone. I am creating different layouts based on the devices, so I want them to view a certain layout based upon whether they are on a Desktop, iPhone or iPad. Is this possible?

       

      Thanks.

        • 1. Re: Script for Detecting iPhone or iPad?
          swheeler

          Get(SystemPlatform) will return a 3 when using a iOS device.

          Get(ApplicationVersion) will return "GO_iPad" and the version (for iPad) or "GO" and the version for (iPhone).

          • 2. Re: Script for Detecting iPhone or iPad?
            Stephen Huston

            Building on swheeler's answer, a rough outline of the script:

             

            IF [ PatternCount ( Get(ApplicationVersion) ; "iPad" ) ≥1 ]

                 Go to Layout (iPadGOLayout)

            ELSE IF [ PatternCount ( Get(ApplicationVersion) ; "go" ) ≥1

                 Go to Layout (iphoneGOLayout)

            Else

                 Go to Layout (FMProLayout)

            End If

            • 3. Re: Script for Detecting iPhone or iPad?
              KenNewell

              Building on others including a calculation that was posted somewhere here before is a custom function that requires no parameters but will return iPhone, iPad, or Desktop to let you know what kind of device is being used.

               

              /*

              ==================================================

              02/25/2011  1.0  KLN  Original Version

              03/21/2012  1.1  KLN  Changed Returned Value Of iPhone/iPod to iPhone

              ==================================================

              PURPOSE:  To determine what device type FM is currently running on

              ==================================================

              */

              Case (

              Left ( Get ( ApplicationVersion ) ; Position ( Get ( ApplicationVersion ) ; " " ; 1 ; 1 ) - 1 ) = "Go" ; "iPhone" ;

              Left ( Get ( ApplicationVersion ) ; Position ( Get ( ApplicationVersion ) ; " " ; 1 ; 1 ) - 1 ) = "Go_iPad" ; "iPad" ;

              "Desktop"

              )

               

               

              I call my custom function GetDevice() and have not had any problems using it.

               

              If GetDevice() = "iPad" . . . goto iPad layout

               

              I like it because it makes my code easier to read as to what I want to do; get the device accessing my DB.

               

              Hope others find this helpful.

              1 of 1 people found this helpful
              • 4. Re: Script for Detecting iPhone or iPad?
                jrenfrew

                Slightly refined version reducing the number of calulation counts

                 

                Let ( [

                _app = Get ( ApplicationVersion ) ;

                _ver = Left ( _app ; Position ( _app ; " " ; 1 ; 1 ) - 1 )

                ] ;

                 

                Case (

                _ver = "Go" ; "iPhone" ;

                _ver = "Go_iPad" ; "iPad" ;

                "Desktop"

                )

                 

                )

                1 of 1 people found this helpful
                • 5. Re: Script for Detecting iPhone or iPad?
                  Vaughan

                  The application version function can return "Server" and "Web" and "xDBC" and "Runtime" amongst others. Lumping these into "desktop" might be misleading.

                  • 6. Re: Script for Detecting iPhone or iPad?
                    KenNewell

                    True.  But in my case it was more a function of which layout to use.  If it was enhanced to include server, web, etc I would change the name of the custom function to something like GetAccess( ) rather than GetDevice ( ) to provide clarity to its purpose.

                    • 7. Re: Script for Detecting iPhone or iPad?
                      WayneMuelver

                      I like the idea. I was looking for something similar to this. In my case, I do need to also find Web Access status. How would you go about modifying your function to do that?

                      • 8. Re: Script for Detecting iPhone or iPad?
                        swheeler

                        One thought would be to script a webviewer to go to google then scrape the website to see if it returns any data.

                         

                        Set Web Viewer["webviewer1";"www.google.com"]

                        Pause/Resume Script (Duration (seconds): 2)]

                        Set Variable[$$WebAccess; If (GetLayoutObjectAttribute ( "webviewer1" ; "content" ) =""; "Not Connected"; "Connected")

                        • 9. Re: Script for Detecting iPhone or iPad?
                          KenNewell

                          Wayne,

                           

                          What do you mean by Web Access status?  If you mean are they connected to FileMaker via the web then take a look at Get(ApplicationVersion) it returns various text strings that you could use to determine web access, runtime etc.  Don't have them off the top of my head but I am very sure web is something that it retuns.

                           

                          If you mean do they have a web connection irreagardless of how connected to FM then Silas' tip above should do the trick or I am sure there might be others as well.  Never had the need so have not spend too much time thinking about it.

                          • 10. Re: Script for Detecting iPhone or iPad?
                            gwinzeler

                                 Set a Variable in your startup file ...

                             

                            Set Variable [$$appVer; Value:

                            Case (

                            PatternCount ( Get ( ApplicationVersion ) ; "Pro" ) = 1 ; "Pro" ;

                            PatternCount ( Get ( ApplicationVersion ) ; "Web" ) = 1 ; "Web" ;

                            PatternCount ( Get ( ApplicationVersion ) ; "iPad" ) = 1 ; "iPad" ;

                            "Phn")

                            ]

                             

                                 Once you have the $$appVer variable set then you can set all your layouts using the "Layout name by Calculation" feature and use this case statement:

                             

                            Go to Layout [

                            Case (

                            $$appVer="Pro" ; "layoutNamePro" ;

                            $$appVer="iPad" ;  "layoutNameiPad" ;

                            $$appVer="Web" ;  "layoutNameWeb" ;

                            "layoutNamePhn" )

                            ]

                             

                            I am currently using this and works great.

                            In my case I only have four possiblities if you need you could of course add more.  Pro is Desktop display and Web we are using IWP.

                            • 11. Re: Script for Detecting iPhone or iPad?
                              WayneMuelver

                              Ken,

                               

                              Yes. Sorry. I thought that was what you meant. So, my solution is accessed on desktops, iPads, iPhones and on the Web with instant web publishing. It sounded like you had an idea to adapt your custom function to look for users who are logged in over the web. I tried out your function and it works great. Now I would just like to use the same function to change my layouts to ones that have a web specific workflow since not all of my normal scripts will work there, like multiple windows that are precisely overlapped a certain way etc. I am sure I can work out the changes I need to make to the custom function, I just thought I would ask because, like I said, it sounded like you had thought about that already.

                               

                              Thanks

                              • 12. Re: Script for Detecting iPhone or iPad?
                                dougnix

                                I just built a custom function based on Ken Newell and jrenfrew's ideas, and it works like a charm. Thanks guys!

                                 

                                I was looking at Gary Winzeler's idea (farther down in this thread), but I wasn't sure how to "set a variable in the startup file". Is this the same as setting the file options to run a calculation using a script trigger?

                                • 13. Re: Script for Detecting iPhone or iPad?
                                  dougnix

                                  Gary, when you say "set a variable in the startup file", what do you mean? Is this the same as running a calculation in a script, triggered when the file is first opened? Can you explain this a bit more for a newbie?

                                  • 14. Re: Script for Detecting iPhone or iPad?
                                    DavidJondreau

                                    I don't think a variable is as good as a custom function.

                                     

                                    Variables can be spoofed by savvy users. That's unlikely but possible. More importantly, there's no centralized location to keep track of variable names. "Did I use $$appVer or $$device.type?" And forget ever changing your variable naming scheme. Even updating your test means you've got to find the script you define the variable in.

                                    1 2 Previous Next