You declared a local variable audioPlayer
to hold a pointer to the player. As soon as your button handler returns the player is being released before it has a chance to play your sound file. Declare a property and use it instead of the local variable.
In YourViewController.m file
@interface YourViewController ()
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@end
or in YourViewController.h file
@interface YourViewController : UIViewController
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@end
Then replace audioPlayer
with self.audioPlayer
in your code.