Search code examples
iosobjective-cavaudioplayernsdatepicker

Add sound to play at time from NSDatePicker


I'm creating a project which requires the user to be able to set a sound to play at a specific time and I'm currently doing that with local notification. I would like to change that to use AVAudioPlayer, and I was wondering, what would be the best approach?

The objects I've got at the moment are a NSDatePicker and a stringFromDate string. My aim is to create an alarm so that the user can set a time using the NSDatePicker and at that time the sound will go off.


Solution

  • Please use Global variable or Class variable to play the alarm.

    @property AVAudioPlayer * player;
    

    ... ...

    _player = [AVAudioPlayer alloc]...
    [_player play];
    

    It'll works fine for your project.