Skip to content

Commit

Permalink
Hook up reports to the current controller in iOS CHIPTool.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Mar 15, 2022
1 parent e6a96ac commit 506762a
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 @@ -216,7 +236,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 506762a

Please sign in to comment.