Check if you run in Simulator (or device)

No replies
OderWat
User offline. Last seen 28 weeks 17 hours ago. Offline
Joined: 4 Jun 2010

I posted this technique in an example program in another thread and fogview made it more universal.

As somebody was looking for something like that I am posting it in this section again:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
---- Check if running on device or simulator ----
onDevice = false                -- assume running on simulator
local path = system.pathForFile("Icon.png", system.ResourceDirectory)
if path and string.sub(path,1,6) ~='/Users' then
        -- Found device if Icon.png found and not in /Users folder
        onDevice = true
end
path = nil
-------------------------------------------------
 
if onDevice then
        print("Running onDevice ...")
else
        print("Running in Simulator ...")
end