Skip to main content
Indentation
ソース リンク
kishikawa katsumi
  • 8,520
  • 2
  • 18
  • 40

現在、Buttonを押すと値を表示しています。
表示をButtonを押さずとも更新して表示し、その値をコンソールにログを出力するにはどうすればいいでしょうか?

#import "ViewController.h"

@interface ViewController () 

//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;

- (IBAction)buttonGetValue:(id)sender;
@end

@implementation ViewController

 

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a[super nib.
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

現在、Buttonを押すと値を表示しています。
表示をButtonを押さずとも更新して表示し、その値をコンソールにログを出力するにはどうすればいいでしょうか?

#import "ViewController.h"

@interface ViewController ()
//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;

- (IBAction)buttonGetValue:(id)sender;
@end

@implementation ViewController

 

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



- (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

現在、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
本文から 1338 文字削除
ソース リンク
FoxTribune
  • 1,237
  • 2
  • 25
  • 52

値に変化が起きたときのRSSI値を、コンソールにログを出力するには?

現在、Buttonを押すと値を表示していますが、
表示をButtonを押さずとも更新して表示し、その値をコンソールにログを出力するにはどうすればいいでしょうか?

#import "ViewController.h"

@interface ViewController ()
//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;
//バッテリー残量
@property (weak, nonatomic) IBOutlet UILabel *labelBatteryCapa;
//RSSI
@property (nonatomic, retain) CLLocationManager *locationManager;
// 緯度
@property (weak, nonatomic) IBOutlet UILabel *labelLatitude;
// 経度
@property (weak, nonatomic) IBOutlet UILabel *labelLongitude;
// 時間


- (IBAction)buttonGetValue:(id)sender;
@end

@implementation ViewController



- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// ユーザから位置情報の利用について承認
if (nil == self.locationManager) {
     self.locationManager = [[CLLocationManager alloc] init];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [ self.locationManager requestWhenInUseAuthorization];
    }
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


- (IBAction)buttonGetValue:(id)sender {

self.labelAntennaBar.text  = [NSString stringWithFormat:@"%zd", [self antennaBar]];
self.labelRssi.text        = [NSString stringWithFormat:@"%zd", [self radioRssi]];
self.labelBatteryCapa.text = [NSString stringWithFormat:@"%zd", [self batteryCapacity]];
 
}


#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];

}


- (NSInteger)batteryCapacity {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] 
valueForKey:@"foregroundView"] subviews];
NSString *dataNetworkItemView = nil;

for (id subview in subviews) {
    if([subview isKindOfClass:
[NSClassFromString(@"UIStatusBarBatteryItemView") class]]) {
        dataNetworkItemView = subview;
        break;
    }
}

return [[dataNetworkItemView valueForKey:@"capacity"] intValue];

}
 

@end

値に変化が起きたときのRSSI値を、コンソールにログを出力するには?

現在、Buttonを押すと値を表示していますが、表示をButtonを押さずとも更新して表示し、値をコンソールにログを出力するにはどうすればいいでしょうか?

#import "ViewController.h"

@interface ViewController ()
//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;
//バッテリー残量
@property (weak, nonatomic) IBOutlet UILabel *labelBatteryCapa;
//RSSI
@property (nonatomic, retain) CLLocationManager *locationManager;
// 緯度
@property (weak, nonatomic) IBOutlet UILabel *labelLatitude;
// 経度
@property (weak, nonatomic) IBOutlet UILabel *labelLongitude;
// 時間


- (IBAction)buttonGetValue:(id)sender;
@end

@implementation ViewController



- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// ユーザから位置情報の利用について承認
if (nil == self.locationManager) {
     self.locationManager = [[CLLocationManager alloc] init];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        [ self.locationManager requestWhenInUseAuthorization];
    }
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


- (IBAction)buttonGetValue:(id)sender {

self.labelAntennaBar.text  = [NSString stringWithFormat:@"%zd", [self antennaBar]];
self.labelRssi.text        = [NSString stringWithFormat:@"%zd", [self radioRssi]];
self.labelBatteryCapa.text = [NSString stringWithFormat:@"%zd", [self batteryCapacity]];
 
}


#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];

}


- (NSInteger)batteryCapacity {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] 
valueForKey:@"foregroundView"] subviews];
NSString *dataNetworkItemView = nil;

for (id subview in subviews) {
    if([subview isKindOfClass:
[NSClassFromString(@"UIStatusBarBatteryItemView") class]]) {
        dataNetworkItemView = subview;
        break;
    }
}

return [[dataNetworkItemView valueForKey:@"capacity"] intValue];

}
 

@end

値に変化が起きたときの値を、コンソールにログを出力するには?

現在、Buttonを押すと値を表示しています
表示をButtonを押さずとも更新して表示し、その値をコンソールにログを出力するにはどうすればいいでしょうか?

#import "ViewController.h"

@interface ViewController ()
//アンテナバー
@property (weak, nonatomic) IBOutlet UILabel *labelAntennaBar;
//RSSI
@property (weak, nonatomic) IBOutlet UILabel *labelRssi;

- (IBAction)buttonGetValue:(id)sender;
@end

@implementation ViewController



- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



- (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
ソース リンク
FoxTribune
  • 1,237
  • 2
  • 25
  • 52
読み込んでいます