Skip to content

Commit

Permalink
Hook up reports to the current controller in iOS CHIPTool. (#16253)
Browse files Browse the repository at this point in the history
Fixes #16198
  • Loading branch information
bzbarsky-apple authored Mar 16, 2022
1 parent 0e23c6a commit 645b03b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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.");
Expand Down Expand Up @@ -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];
}
}
}
}
Expand Down

0 comments on commit 645b03b

Please sign in to comment.