Determining Device

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Determining Device

Post by richardmac » Wed Nov 14, 2012 9:43 pm

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?

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Determining Device

Post by endernafi » Wed Nov 14, 2012 10:52 pm

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
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: Determining Device

Post by richardmac » Thu Nov 15, 2012 5:05 am

Nice! Thanks very much for sharing that script.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Determining Device

Post by Jellicle » Tue Nov 27, 2012 10:35 am

This script is returning iPhone 4/4s for me when run against the iPhone 5/iOS 6 simulator :(

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Determining Device

Post by endernafi » Tue Nov 27, 2012 10:45 am

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
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Determining Device

Post by Jellicle » Tue Nov 27, 2012 11:03 am

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
14" MacBook Pro
Former LiveCode developer.
Now recovering.

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Determining Device

Post by endernafi » Tue Nov 27, 2012 11:10 am

Ok, I'm glad that you explained.
I've learned one more thing, meaning that "force the simulator" thing.

Thanks, Gerry...

Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Determining Device

Post by marcelloe » Mon Nov 11, 2013 9:34 pm

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.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Determining Device

Post by Nakia » Mon Nov 11, 2013 10:29 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Determining Device

Post by Simon » Mon Nov 11, 2013 10:33 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Determining Device

Post by marcelloe » Mon Nov 11, 2013 11:03 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Determining Device

Post by Simon » Mon Nov 11, 2013 11:38 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Determining Device

Post by endernafi » Tue Nov 12, 2013 1:14 am

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
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

marcelloe
Posts: 140
Joined: Thu Oct 17, 2013 2:26 pm

Re: Determining Device

Post by marcelloe » Tue Nov 12, 2013 4:44 pm

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

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Determining Device

Post by endernafi » Tue Nov 12, 2013 4:58 pm

Hi Marcelloe,

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


Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Post Reply

Return to “iOS Deployment”