Page 1 of 1

First launch breaks the location tracking

Posted: Mon Jul 04, 2011 10:36 am
by doobox
Hi there,

I essentially have the app nearly the way i want it.. But....!

The first launch when installed on a real device fails to return the values from on location changed.
This is something to do with the fact that i am in on preOpenCard, creating a data stack, as if i dont create that data stack, it works as expected.

It is as if i have something in the code that is firing before the data stack is created that depends on it. But i cant really see that i have.
If i close the app on the device and restart the app it all works as expected.

Code: Select all

global tDataPath

on preOpenCard
   put specialFolderPath("documents") into tDataPath
   put tDataPath & "/virtAppData.livecode" into tDataPath
   
   if not (there is a file tDataPath) then
      create stack "vertDataStack"
      put it into temp
      set the visible of temp to false
      set the filename of temp to tDataPath
      save temp
      go stack "vertigo"
   end if
   
   # mobGUIStart ---> Inserted by mobGUI plugin
   if "MobGUILib-1309576541555.448975" is not among the lines of the stacksInUse then start using stack "MobGUILib-1309576541555.448975"
   mobGUIPreOpenCard me
   # mobGUIEnd
end preOpenCard

on openCard
   iphoneStartTrackingLocation
   put the alltimehigh of stack tDataPath into field "alltimehigh"
end openCard


on locationChanged
   put iphoneCurrentLocation() into tLocation
   put the round of tLocation["altitude"] into tHeightInMeters
   put tHeightInMeters * 3.280839895 into tHeightInFeet
   put the round of tHeightInFeet into tHeightInFeet
   put field "units" into tFeetOrMeters
   
   if tFeetOrMeters = "Ft" then
      send "tmUpdateGauge" && tHeightInFeet to group "howhigh"
   else
      send "tmUpdateGauge" && tHeightInMeters to group "howhigh"
   end if
   
   if  tHeightInMeters > the alltimehigh of stack tDataPath  then
         put tHeightInMeters into field "allTimeHigh"
      set the alltimehigh of stack tDataPath to tHeightInMeters
   end if
   
end locationChanged


on locationError
    answer "The current location cannot be determined."
end locationError


on closeCard
   iphoneStopTrackingLocation
   save stack tDataPath
end closeCard

Re: First launch breaks the location tracking

Posted: Mon Jul 04, 2011 10:56 am
by doobox
Debugging shows that:

Code: Select all

on openCard
   iphoneStartTrackingLocation -- works every time even on first run
end openCard


on locationChanged
 -- never fires on first run... always fires on subsequent runs
end locationChanged

Re: First launch breaks the location tracking

Posted: Mon Jul 04, 2011 4:53 pm
by doobox
Stripped this to the bare bones...!
and for some reason, creating a data stack on pre open stack,
does indeed stop the on locationChanged message...?

if you comment out the preOpenStack section it works on first launch.... Why's that then...?

Code: Select all

global tDataPath


-- if you comment out the creation of the data stack
-- the on locationChanged works on first launch, else it does not work on first launch
on preOpenStack
   put specialFolderPath("documents") & "/DataFile.livecode" into tDataPath
   
   if not (there is a file tDataPath) then
      create stack "Data"
      put it into tTemp
      set the visible of tTemp to false
      set the filename of tTemp to tDataPath
      save tTemp
      go stack "testlaunch"
   end if
end preOpenStack


on openStack
   iphoneStartTrackingLocation
end openStack



on locationChanged
   put iphoneCurrentLocation() into tLocation
   put the round of tLocation["altitude"] into tTheHeight
   put tTheHeight & cr after field "result"
end locationChanged



on locationError
    answer "The current location cannot be determined."
end locationError


on closeStack
   iphoneStopTrackingLocation
   save stack tDataPath
end closeStack

Re: First launch breaks the location tracking

Posted: Mon Jul 04, 2011 5:55 pm
by doobox
If anyone's interested, the location changed is sent to the default stack.

Craeting the data stack as i did meant that the main stack was no longer the default on first launch.

The addition of
set the defaultStack to "vertigo"
fixed it:

Code: Select all

on preOpenStack
   put specialFolderPath("documents") & "/DataFile.livecode" into tDataPath
   
   if not (there is a file tDataPath) then
      create stack "Data"
      put it into tTemp
      set the visible of tTemp to false
      set the filename of tTemp to tDataPath
      save tTemp
      set the defaultStack to "vertigo" -- addition to make the main vertigo stack the default
      go stack "testlaunch"
   end if
end preOpenStack