Page 1 of 2

Determining Device

Posted: Wed Nov 14, 2012 9:43 pm
by richardmac
Quick question. On opening a stack, what is the best way to determine if LiveCode is running on an iPad 1, 2, or mini, iPad 3 or 4, iPhone 3GS, 4GS, or 5?

Re: Determining Device

Posted: Wed Nov 14, 2012 10:52 pm
by endernafi
Hi Richard,

I'm sure that there are other possible ways to get this info,
but here is a simple one:

Code: Select all

on preOpenStack
   iphoneUseDeviceResolution true, true
   put determineDevice() into theDevice
end preOpenStack

function determineDevice
   switch the machine
      case "iPod Touch"
         switch
            case (the screenLoc is "160,240") or (the screenLoc is "240,160")
               return "iPod Touch 3 or older iPod Touch"
               break
            case (the screenLoc is "320,480") or (the screenLoc is "480,320")
               return "iPod Touch 4"
               break
            case (the screenLoc is "320,568") or (the screenLoc is "568,320")
               return "iPod Touch 5"
               break
         end switch
         break
      case "iPhone"
         switch
            case (the screenLoc is "160,240") or (the screenLoc is "240,160")
               return "iPhone3GS or older iPhone"
               break
            case (the screenLoc is "320,480") or (the screenLoc is "480,320")
               return "iPhone 4 or iPhone 4S"
               break
            case (the screenLoc is "320,568") or (the screenLoc is "568,320")
               return "iPhone 5"
               break
         end switch
         break
      case "iPhone Simulator"
         switch
            case (the screenLoc is "160,240") or (the screenLoc is "240,160")
               return "Simulator - iPhone3GS or older iPhone"
               break
            case (the screenLoc is "320,480") or (the screenLoc is "480,320")
               return "Simulator - iPhone 4 or iPhone 4S"
               break
            case (the screenLoc is "320,568") or (the screenLoc is "568,320")
               return "Simulator - iPhone 5"
               break
         end switch
         break
      case "iPad"
         switch
            case (the screenLoc is "384,512") or (the screenLoc is "512,384")
               return "iPad 1, iPad 2 or iPad Mini"
               break
            case (the screenLoc is "768,1024") or (the screenLoc is "1024,768")
               return "iPad 3"
               break
         end switch
         break
      case "iPad Simulator"
         switch
            case (the screenLoc is "384,512") or (the screenLoc is "512,384")
               return "Simulator - iPad 1, iPad 2 or iPad Mini"
               break
            case (the screenLoc is "768,1024") or (the screenLoc is "1024,768")
               return "Simulator - iPad 3"
               break
         end switch
         break
   end switch
end determineDevice

Best,

~ Ender Nafi Elekçioğlu

Re: Determining Device

Posted: Thu Nov 15, 2012 5:05 am
by richardmac
Nice! Thanks very much for sharing that script.

Re: Determining Device

Posted: Tue Nov 27, 2012 10:35 am
by Jellicle
This script is returning iPhone 4/4s for me when run against the iPhone 5/iOS 6 simulator :(

Gerry

Re: Determining Device

Posted: Tue Nov 27, 2012 10:45 am
by endernafi
Hi Gerry,

I checked it again and it works correct as you can see in the attached screenshot.
Maybe something's wrong with your settings?
Did you include iphoneUseDeviceResolution true, true in the preOpenStack handler?
Screen Shot 2012-11-27 at 11.44.04 AM.jpg

Re: Determining Device

Posted: Tue Nov 27, 2012 11:03 am
by Jellicle
Yes, I'm using iphoneUseDeviceResolution true, true.

However, I had forgotten that I'd modified the LC runtime defaults by removing the Default4InchSplash.png files for the simulator and device in the LC app bundle, as I was previously needing to force the simulator to centre an iPhone 4/3.5 inch-sized app on the iPhone's 4 inch screen (if those files are present the smaller app will expand to fill the whole iPhone 5 screen size). Once I restored the Default4InchSplash.png files your script worked :)

Thanks, and apologies.

Gerry

Re: Determining Device

Posted: Tue Nov 27, 2012 11:10 am
by endernafi
Ok, I'm glad that you explained.
I've learned one more thing, meaning that "force the simulator" thing.

Thanks, Gerry...

Best,

~ Ender Nafi

Re: Determining Device

Posted: Mon Nov 11, 2013 9:34 pm
by marcelloe
Does this script that Ender posted still work? I can't get it to work on my stack. I get a execution error at line 2 (Handler: con't find Handler) near "iphoneUseDeviceResolution", char 1.

Re: Determining Device

Posted: Mon Nov 11, 2013 10:29 pm
by Nakia
For what it is worth this question was asked a small while back in this thread.
http://www.forums.runrev.com/viewtopic.php?f=49&t=17828

You will find in that thread a link to a Git Repository with a LC External that should return the device string. Note: It doesn't work on the simulator for some reason.

Re: Determining Device

Posted: Mon Nov 11, 2013 10:33 pm
by Simon
Hi marcelloe,
The posted script will only run on a iPhone or in the simulator, not in the IDE.
You will have to add scripts to check where the app is running e.g.
if the environment is "mobile" then
--do the iPhone stuff

Simon

Re: Determining Device

Posted: Mon Nov 11, 2013 11:03 pm
by marcelloe
I built my app for Iphone 320X480. Is there away to scale it to IDevices? I know LC 6.5 is suppose to do this but I can't get anything to work. I am new to this and I am learning as I go. Any help would be appreciated.

Re: Determining Device

Posted: Mon Nov 11, 2013 11:38 pm
by Simon
Here are beginner resources for you:
http://lessons.runrev.com/
http://www.hyperactivesw.com/revscriptc ... ences.html

Read also the User Guide and the release notes for ver. 6.5.x

Here is a posting to your question:
http://forums.runrev.com/viewtopic.php?f=7&t=17763

Simon

Re: Determining Device

Posted: Tue Nov 12, 2013 1:14 am
by endernafi
First; yes, the script works fine; I'm still using it.
But, as Simon stated, you have to constrain it to mobile devices.
Simon's code must be added to mine.


A word about the Livecode 6.5, though...
This deserves a separate thread actually, but anyways.

A very important point to notice regarding Resolution Independence is that it doesn't relocate - reposition your controls.
It's explained in an issue of Newsletters.
It's not magic, it's not Geometry Manager, it's a scaler.

The programmer have to deal with the repositioning problem.
Let's say we have 2 images at 240*240px, placed one on top of another in the card.

In iPhone 3, they'll be 240*240px;
In iPhone 4, they'll be 480*480px;
In iPhone 5, they still should be 480*480px not a stretched 480*568px.
It'll look bad.
They just need to be repositioned and move off from each other a little to have a nice, fit layout.

Just putting a line of code into your script won't get it done.

So, one have to start to practice the basics of scaling-repositioning.
Do it yourself learning from the experienced programmers' scripts.
Write your own script to support different screen resolutions.
Then, you can make use of the boons of our lovely Livecode.


Best,

~ Ender Nafi

Re: Determining Device

Posted: Tue Nov 12, 2013 4:44 pm
by marcelloe
I have spent all of last night reading and trying to figure out how script the app to either select iphone or ipad depending on the device it was opened on. In the dictionary I haven't found anything to select ipad. Maybe I am overlooking it. Can someone point me in the right direction. Is the below script anywhere in the right direction.

on preOpenStack
if the environment is "mobile" then
if the platform is "iphone" then
iphoneUseDeviceResolution true, true
put determineDevice() into theDevice
end preOpenStack

Re: Determining Device

Posted: Tue Nov 12, 2013 4:58 pm
by endernafi
Hi Marcelloe,

Try this sample stack:
deviceIdentifier.zip
(1.53 KiB) Downloaded 287 times
Hope it helps...


Best,

~ Ender Nafi