iOS Question BackGround Code

Discussion in 'iOS Questions' started by MarcoRome, Jun 8, 2018.

  1. MarcoRome

    MarcoRome Expert Licensed User

    Hi all, i have this code:

    Code:
    'Code module
    #Region  Project Attributes
        
    #ApplicationLabel: B4i Background
        
    #Version: 1.0.0
        
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
        #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
        
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
        
    #Target: iPhone, iPad
        
    #ATSEnabled: True
        
    #MinVersion: 8
    #End Region

    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
        
    Dim rileggi_query As Timer

    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.Title = 
    "Page 1"
        Page1.RootPanel.Color = 
    Colors.White
        NavControl.ShowPage(Page1)
        
        
    'For Notification
        App.RegisterUserNotifications(TrueTrueTrue'request permission for notifications
        App.ApplicationIconBadgeNumber = 0
        
    'check whether the app was started from a notification
        If App.LaunchOptions.IsInitialized Then
            
    Dim ln As Notification  = App.LaunchOptions.Get("UIApplicationLaunchOptionsLocalNotificationKey")
            
    If ln.IsInitialized Then
                
    'hd.ToastMessageShow("Application was started from a notification: " & ln.AlertBody, True)
                Log("Application was started from a notification")
            
    End If
        
    End If

    End Sub


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

    Private Sub Application_Background
        
    Log("i'm background")
        rileggi_query.Initialize(
    "rileggi_query"5000)
        rileggi_query.Enabled = 
    True
    End Sub

    Private Sub Application_Foreground
        App.ApplicationIconBadgeNumber=
    0
        rileggi_query.Enabled = 
    False
    End Sub

    Sub rileggi_query_Tick
        
    Log("Timer Action")
        
    'Here you can call anything
        Dim ln As Notification
        ln.Initialize(
    DateTime.Now)
        ln.IconBadgeNumber = 
    1
        ln.AlertBody = 
    "Query..."
        ln.PlaySound = 
    True
        ln.Register
    End Sub

    Sub Application_ReceiveLocalNotification (ln As Notification)
        
    'this event will fire if the scheduled notification happend when the app was running
        hd.ToastMessageShow("NA: " & ln.AlertBody, True)
    End Sub
    and all work in debug, if i have app in background every 5 sec i have notification.
    But dont work if i compile in release mode.
    Any suggestion ?
    Thank you
    Marco
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It will only work in debug mode for a minute or two. It will not help you if you need to run something in the background.
     
    MarcoRome likes this.
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