Skip to content

Commit 42fef75

Browse files
authored
Merge pull request #120 from romedius/patch-1
CB-11513: (ios) Fixed: iOS memory warning stops sound, but does not send status to JS-client
2 parents a7e376a + ad25d10 commit 42fef75

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/ios/CDVSound.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,31 @@ -(void)itemStalledPlaying:(NSNotification *) notification {
833833

834834
- (void)onMemoryWarning
835835
{
836-
[[self soundCache] removeAllObjects];
837-
[self setSoundCache:nil];
836+
/* https://issues.apache.org/jira/browse/CB-11513 */
837+
NSMutableArray* keysToRemove = [[NSMutableArray alloc] init];
838+
839+
for(id key in [self soundCache]) {
840+
CDVAudioFile* audioFile = [[self soundCache] objectForKey:key];
841+
if (audioFile != nil) {
842+
if (audioFile.player != nil && ![audioFile.player isPlaying]) {
843+
[keysToRemove addObject:key];
844+
}
845+
if (audioFile.recorder != nil && ![audioFile.recorder isRecording]) {
846+
[keysToRemove addObject:key];
847+
}
848+
}
849+
}
850+
851+
[[self soundCache] removeObjectsForKeys:keysToRemove];
852+
853+
// [[self soundCache] removeAllObjects];
854+
// [self setSoundCache:nil];
838855
[self setAvSession:nil];
839856

840857
[super onMemoryWarning];
841858
}
842859

860+
843861
- (void)dealloc
844862
{
845863
[[self soundCache] removeAllObjects];

0 commit comments

Comments
 (0)