iOS Question BackGround Code

MarcoRome

Expert
Licensed User
Longtime User
Hi all, i have this code:

B4X:
'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(True, True, True) '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
 
Top