From 0740cdfe924d6ff496d26efca36ee1530b384bec Mon Sep 17 00:00:00 2001 From: Renaud Jenny <renaud.jenny@tomtom.com> Date: Mon, 27 Jan 2020 11:34:38 +0000 Subject: [PATCH] fix(SoundVolume): addVolumeListener callback have same behaviour * Fix SoundVolume addVolumeListener callback have the same behaviour on Android and iOS * Fix #102 * Fix c19354837/react-native-system-setting/issues/102 --- ios/RTCSystemSetting.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ios/RTCSystemSetting.m b/ios/RTCSystemSetting.m index c94aaad..aceb107 100644 --- a/ios/RTCSystemSetting.m +++ b/ios/RTCSystemSetting.m @@ -96,10 +96,18 @@ +(BOOL)requiresMainQueueSetup{ } RCT_EXPORT_METHOD(setVolume:(float)val config:(NSDictionary *)config){ + [self stopObserving]; + dispatch_sync(dispatch_get_main_queue(), ^{ id showUI = [config objectForKey:@"showUI"]; [self showVolumeUI:(showUI != nil && [showUI boolValue])]; volumeSlider.value = val; + + __weak RCTSystemSetting *weakSelf = self; + [[NSNotificationCenter defaultCenter] addObserverForName:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { + __strong RCTSystemSetting *strongSelf = weakSelf; + [strongSelf startObserving]; + }]; }); }