値に変化が起きたときの値を、コンソールにログを出力するには?
現在、Buttonを押すと値を表示しています。
表示をButtonを押さずとも更新して表示し、その値をコンソールにログを出力するにはどうすればいいでしょうか?
#import "ViewController.h"
@interface ViewController ()
//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)buttonGetValue:(id)sender {
self.labelAntennaBar.text = [NSString stringWithFormat:@"%zd", [self antennaBar]];
self.labelRssi.text = [NSString stringWithFormat:@"%zd", [self radioRssi]];
}
#pragma mark - Status bar
- (NSInteger )antennaBar {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"]
valueForKey:@"foregroundView"] subviews];
NSString *dataNetworkItemView = nil;
for (id subview in subviews) {
if ([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
return [[dataNetworkItemView valueForKey:@"signalStrengthBars"] intValue];
}
- (NSInteger )radioRssi {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"]
valueForKey:@"foregroundView"] subviews];
NSString *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
return [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];
}
@end