iOS Question Need to choose background reason

rfresh

Well-Known Member
Licensed User
I have a timer app that runs a Clock. This app will be used to help pilots time their instrument approaches, so it’s a critical app that needs to run if in the background. However, I did not see any Clock or timer component on Apple’s list of acceptable tasks to keep an app running if moved to the background. Will picking ‘Audio’ work or do I actually need to be playing a sound file if I choose audio? I only need to run a Clock.
 

Erel

Administrator
Staff member
Licensed User
Do you plan to release it to the app store? If so then you should probably treat it as a navigation app and monitor the location in the background.
 

rfresh

Well-Known Member
Licensed User
No, I do not plan to release it to the app store. The app will be distributed via Diawi.com into a private community of pilots.
 

Erel

Administrator
Staff member
Licensed User
Audio will not work without you playing something all the time. It will probably be easier with background location.
 

rfresh

Well-Known Member
Licensed User
Thanks Erel. I got the Location method working with the help of your location example app.
 

rfresh

Well-Known Member
Licensed User
I'm having a problem with my app running the timer in the background. I'm using the location method to keep the app alive in the background and the heading is updating OK in the BG and FG. If I'm running in development mode, the Clock continues to run in the BG. When I bring it to the FG I see the time jump so I know it's keeping count.

When I make a release build and install via diawi.com, the Clock doesn't run in the BG. If the timer says 20 when I call up another app and I wait about 10 secs and then call up my app, the count resumes at 21 so it's not counting while in the BG.

Is this being caused because of being installed by diawi.com? In other words, is this being caused because I'm 'sideloading' the app from a third party service?

I did a save as zip file but it was too large (3,000 kb) to upload so here is my main code page:

B4X:
'Code module
#Region  Project Attributes 
    #ApplicationLabel: Test3
    #Version: 1.0.0 
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait
    #iPadOrientations: Portrait
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 7
    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Used to keep the countdown timer running.</string>
    #PlistExtra:<key>NSLocationUsageDescription</key><string>Used to keep the countdown timer running.</string>
#End Region

#CertificateFile: ios_distribution.cer
#ProvisionFile: ad_hoc.mobileprovision
#IgnoreWarnings: 32

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private LocManager As LocationManager
   
    Private countDownTimer As Timer
   
    Dim intSeconds As Int

    Private ButtonStart As Button
    Private ButtonStop As Button
    Private Label_Enable As Label
    Private Label_Compass As Label
    Private Label_Counter As Label
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    LocManager.Initialize("LocManager")
   
    Page1.RootPanel.LoadLayout("Main")
    Page1.Title = "Test3"
   
    countDownTimer.Initialize("countDownTimer", 1000)
   
    intSeconds = 0
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Foreground
    StartLocationUpdates
End Sub

Private Sub Application_Background
    'LocManager.Stop
    'LocManager.StopHeading
End Sub

Private Sub LocManager_AuthorizationStatusChanged (Status As Int)
    Label_Enable.Visible = (LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_DENIED _
     Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_RESTRICTED)
    StartLocationUpdates
End Sub

Private Sub StartLocationUpdates
    'if the user allowed us to use the location service or if we never asked the user before then we call LocationManager.Start.
    If LocManager.IsAuthorized Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_NOT_DETERMINED Then
        LocManager.Start(0)
    End If
    LocManager.StartHeading
End Sub

Private Sub LocManager_HeadingChanged (MagneticHeading As Double, TrueHeading As Double)
    Label_Compass.Text = NumberFormat(MagneticHeading, 1, 0)
End Sub

Sub countDownTimer_Tick
    intSeconds = intSeconds + 1
    Label_Counter.Text = intSeconds
End Sub


Sub ButtonStart_Click
    intSeconds = 0
    countDownTimer.Enabled = True
End Sub

Sub ButtonStop_Click
    countDownTimer.Enabled = False
End Sub
[/CODE
 
Top