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

Discussion in 'iOS Questions' started by hanyelmehy, Jun 12, 2015.

  1. hanyelmehy

    hanyelmehy Active Member Licensed User

    can i play custom sound file for local (or scheduled) notifications
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes. Manually put the sound file in Files\SpecialFolder.

    Set it with:
    Code:
    Dim no As NativeObject = Notification1
    no.SetField(
    "soundName""soundfile")
     
    hanyelmehy likes this.
  3. megaB4x

    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

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

    Erel Administrator Staff Member Licensed User

    You should run this code before you register the notification (the code itself is correct).
     
  5. megaB4x

    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?

    Code:
    '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(
    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)
            
    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You cannot set the "soundName" field before ln is initialized.
     
  7. megaB4x

    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!
     
    Erel likes this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    No need. Thank you :)
     
  9. hanyelmehy

    hanyelmehy Active Member Licensed User

    did notifications support only wav file ,when try using mp3 notifications not play it
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    The sound duration must be shorter than 30 seconds.
     
Loading...