Skip to content

Commit

Permalink
feat: add simulator check, session category
Browse files Browse the repository at this point in the history
  • Loading branch information
yigithanyucedag committed Jul 29, 2024
1 parent 52b24b5 commit 5de875c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ios/Pitchy.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "Pitchy.h"
#import <AVFoundation/AVFoundation.h>
#import <React/RCTLog.h>

@implementation Pitchy {
AVAudioEngine *audioEngine;
Expand All @@ -16,6 +17,10 @@ @implementation Pitchy {
}

RCT_EXPORT_METHOD(init:(NSDictionary *)config) {
#if TARGET_IPHONE_SIMULATOR
RCTLogInfo(@"Pitchy module is not supported on the iOS simulator");
return;
#endif
if (!isInitialized) {
audioEngine = [[AVAudioEngine alloc] init];
AVAudioInputNode *inputNode = [audioEngine inputNode];
Expand All @@ -28,6 +33,21 @@ @implementation Pitchy {
[self detectPitch:buffer];
}];

AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error = nil;
[session setCategory:AVAudioSessionCategoryPlayAndRecord
mode:AVAudioSessionModeMeasurement
options:AVAudioSessionCategoryOptionDefaultToSpeaker
error:&error];
if (error) {
RCTLogError(@"Error setting AVAudioSession category: %@", error);
}

[session setActive:YES error:&error];
if (error) {
RCTLogError(@"Error activating AVAudioSession: %@", error);
}

isInitialized = YES;
}
}
Expand Down

0 comments on commit 5de875c

Please sign in to comment.