From ad25d1059c44ce2229c40dabf6b7136f89356952 Mon Sep 17 00:00:00 2001 From: Romedius Weiss Date: Fri, 4 Nov 2016 14:17:04 +0100 Subject: [PATCH] Fix for CB-11513 https://issues.apache.org/jira/browse/CB-11513 --- src/ios/CDVSound.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m index 97f5d6e5..278f8547 100644 --- a/src/ios/CDVSound.m +++ b/src/ios/CDVSound.m @@ -836,13 +836,31 @@ -(void)itemStalledPlaying:(NSNotification *) notification { - (void)onMemoryWarning { - [[self soundCache] removeAllObjects]; - [self setSoundCache:nil]; + /* https://issues.apache.org/jira/browse/CB-11513 */ + NSMutableArray* keysToRemove = [[NSMutableArray alloc] init]; + + for(id key in [self soundCache]) { + CDVAudioFile* audioFile = [[self soundCache] objectForKey:key]; + if (audioFile != nil) { + if (audioFile.player != nil && ![audioFile.player isPlaying]) { + [keysToRemove addObject:key]; + } + if (audioFile.recorder != nil && ![audioFile.recorder isRecording]) { + [keysToRemove addObject:key]; + } + } + } + + [[self soundCache] removeObjectsForKeys:keysToRemove]; + + // [[self soundCache] removeAllObjects]; + // [self setSoundCache:nil]; [self setAvSession:nil]; [super onMemoryWarning]; } + - (void)dealloc { [[self soundCache] removeAllObjects];