Skip to content
This repository was archived by the owner on Aug 21, 2020. It is now read-only.

[iOS] Deactivating recording session if needed, on app background #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ios/AudioRecorderManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <React/RCTUtils.h>
#import <React/RCTEventDispatcher.h>
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>

NSString *const AudioRecorderEventProgress = @"recordingProgress";
NSString *const AudioRecorderEventFinished = @"recordingFinished";
Expand Down Expand Up @@ -39,6 +40,25 @@ @implementation AudioRecorderManager {

RCT_EXPORT_MODULE();

- (instancetype)init
{
self = [super init];
if (self) {
[self registerForNotifications];
}
return self;
}

- (void)registerForNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive) name: UIApplicationWillResignActiveNotification object: nil];
}

- (void)applicationWillResignActive {
if (_audioRecorder && !_audioRecorder.isRecording) {
[_recordSession setActive:NO error: nil];
}
}

+ (BOOL)requiresMainQueueSetup {
return YES;
}
Expand Down