iOS Question Need to choose background reason

Discussion in 'iOS Questions' started by rfresh, May 13, 2019.

  1. rfresh

    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.
     
  2. Erel

    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.
     
  3. rfresh

    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.
     
  4. Erel

    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.
     
  5. rfresh

    rfresh Well-Known Member Licensed User

    Thanks Erel. I got the Location method working with the help of your location example app.
     
  6. rfresh

    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:

    Code:
    '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, 10)
    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
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. rfresh

    rfresh Well-Known Member Licensed User

    Got it working now...thanks again...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice