I searched through all the questions for this topic here on stack overflow, but I can't seem to figure it out, since I seem to do everything right, still I get this error. I'm trying to implement a recording button for my chat, which records as long as the button is pressed. I always get the following error: [HenrysApp.ChatViewController longPress:]: unrecognized selector sent to instance 0x7f952602dc00
Here is the code:
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "longPress:")
longPressGestureRecognizer.minimumPressDuration = 1
self.recordingSession = AVAudioSession.sharedInstance()
do {
try self.recordingSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try self.recordingSession.setActive(true)
self.recordingSession.requestRecordPermission() { [unowned self] allowed in
DispatchQueue.main.async {
if allowed {
self.record_button.addGestureRecognizer(longPressGestureRecognizer)
} else {
// failed to record!
}
}
}
} catch {
// failed to record!
}
// Gesture Recognizer for the Record Button, so as long as it is pressed, record!
func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer){
if longPressGestureRecognizer.state == .began {
print("long press began")
let recordingTapImage = UIImage(named: "ic_mic_none_white")
record_button.setImage(recordingTapImage, for: .normal)
self.recording()
}
if longPressGestureRecognizer.state == .ended {
print("long press ended")
let recordImage = UIImage(named: "ic_mic_white")
record_button.setImage(recordImage, for: .normal)
self.recordTapRelease()
}
}