How to play alarm tone in xamarin ios when local notification fires at specific time

Viewed 215

I have an app in xamarin ios in which I want to play alarm tone when notification fires and stop when user dismiss the notification. How can I achieve this ?

1 Answers

Take a look at UNNotificationSound , it is used to customize sound played upon delivery of a notification.

For local notifications, assign the sound object to the sound property of your UNMutableNotificationContent object.

Sample code

var content = new UNMutableNotificationContent();
content.Title = "Title";
content.Sound =  UNNotificationSound.GetCriticalSound("a.aiff");

var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(5, false);
var request = UNNotificationRequest.FromIdentifier("a", content,trigger);
UNUserNotificationCenter.Current.AddNotificationRequest(request, null);

Notice

  1. Place the sound file in the following locations :

    • The /Library/Sounds directory of the app’s container directory.
    • The /Library/Sounds directory of one of the app’s shared group container directories.
    • The main bundle of the current executable.
  2. The sound must be in one of the following audio data formats:

    • Linear PCM

    • MA4 (IMA/ADPCM)

    • µLaw

    • aLaw

    You can package the audio data in an aiff, wav, or caf file.

  3. Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead.

Related