iOS Question play custom sound file for local (or scheduled) notifications

megaB4x

Member
Licensed User
Hi,

I dropped a "test.wav" in Files\Special folder then added code as below. I am not sure what to put in soundName placeholder.
Also, "soundfile" should be the file name as below?

Thanks

B4X:
Sub Application_ReceiveLocalNotification (LN As Notification)
    hd.ToastMessageShow("Notification arrived: " & LN.AlertBody, True)
    Dim no As NativeObject = LN
    no.SetField("soundName", "test.wav")
End Sub
 

megaB4x

Member
Licensed User
HI Erel,
Below is the demo local notification code, I added only three lines. I built on release mode but application won't load on device. Don't see any error messages either.
Is the code in right location?

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#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
    Private hd As HUD
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    Page1.RootPanel.LoadLayout("1")
    NavControl.ShowPage(Page1)
   
    Dim ln As Notification
    Dim no As NativeObject = ln
    no.SetField("soundName", "test.wav")
   
    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)
        End If
    End If
End Sub


Sub btnNotification_Click
    Dim ln As Notification
    ln.Initialize(DateTime.Now + 6 * DateTime.TicksPerSecond) '6 seconds from now
    ln.IconBadgeNumber = 1
    ln.AlertBody = "Moo is hungry"
    ln.PlaySound = True
    ln.Register
    hd.ToastMessageShow("Notification will fire in 6 seconds.", False)
End Sub

Sub Application_ReceiveLocalNotification (LN As Notification)
    'this event will fire if the scheduled notification happend when the app was running
    hd.ToastMessageShow("Notification arrived: " & LN.AlertBody, True)
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub
 

megaB4x

Member
Licensed User
Thanks Erel that worked!!!

Is there a link where we can donate using PayPal to support your products/services? We understand that you are busy and the level of support you provide is exceptional and just unheard of. Thanks again!
 
Top