diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.h b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.h index 49c4699089d4b9..93bb9a79e2bc03 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.h +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.h @@ -13,6 +13,11 @@ NS_ASSUME_NONNULL_BEGIN @interface TemperatureSensorViewController : UIViewController +/** + * Return the current controller, if any. + */ ++ (nullable TemperatureSensorViewController *)currentController; + @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m index 1f657b9103aa2f..bb003b634505ba 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Temperature Sensor/TemperatureSensorViewController.m @@ -18,12 +18,15 @@ @interface TemperatureSensorViewController () @property (nonatomic, strong) UIButton * sendReportingSetup; @end +static TemperatureSensorViewController * _Nullable sCurrentController = nil; + @implementation TemperatureSensorViewController // MARK: UIViewController methods - (void)viewDidLoad { + sCurrentController = self; [super viewDidLoad]; [self setupUI]; @@ -33,6 +36,23 @@ - (void)viewDidLoad [self readCurrentTemperature]; } +- (void)viewWillDisappear:(BOOL)animated +{ + sCurrentController = nil; + [super viewWillDisappear:animated]; +} + +- (void)viewDidAppear:(BOOL)animated +{ + sCurrentController = self; + [super viewDidAppear:animated]; +} + ++ (nullable TemperatureSensorViewController *)currentController +{ + return sCurrentController; +} + - (IBAction)sendReportingSetup:(id)sender { NSLog(@"Status: User request to send reporting setup."); @@ -217,7 +237,10 @@ - (void)reportFromUserEnteredSettings if (report.error != nil) { NSLog(@"Error reading temperature: %@", report.error); } else { - [self updateTempInUI:((NSNumber *) report.value).shortValue]; + __auto_type controller = [TemperatureSensorViewController currentController]; + if (controller != nil) { + [controller updateTempInUI:((NSNumber *) report.value).shortValue]; + } } } }