为什么我无法获取 UIStatusBarSignalStrengthItemView?
Why can not I get UIStatusBarSignalStrengthItemView?
为了获取 iphone 上的 wifi 或蜂窝信号强度,
我写了以下代码作为各种网站的参考,
但它不出现在 IF 语句中
"UIStatusBarSignalStrengthItemView" 或“_UIStatusBarCellularSignalView”。
您需要许可吗?
■开发环境
Xcode9.4.1
iPhoneX‖iOS:11.0.1
■Test1.m
#import "Test1.h"
@implementation Test1 : NSObject
- (int)antennaBar
{
NSLog(@"%@",[[[UIApplication sharedApplication] valueForKeyPath:@"statusBar"] subviews]);
NSLog(@"antennaBar 1");
NSLog(@"antennaBar 2");
// NSArray *subviews = [[[apps valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSArray *subviews = nil;
NSLog(@"antennaBar 3");
id statusBar = [[UIApplication sharedApplication] valueForKey:@"statusBar"];
NSLog(@"antennaBar 4");
if ([statusBar isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
NSLog(@"antennaBar 5");
subviews = [[[statusBar valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
} else {
NSLog(@"antennaBar 6");
subviews = [[statusBar valueForKey:@"foregroundView"] subviews];
}
NSLog(@"antennaBar 7");
NSString *dataNetworkItemView = nil;
NSLog(@"antennaBar 8");
for (id subview in subviews) {
NSLog(@"Class - %@", NSStringFromClass([subview class]));
NSLog(@"antennaBar aaaaaaa");
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
NSLog(@"antennaBar bbbbbb");
dataNetworkItemView = subview;
break;
}
if([subview isKindOfClass:[NSClassFromString(@"_UIStatusBarCellularSignalView") class]]) {
NSLog(@"antennaBar eeeeee");
dataNetworkItemView = subview;
int fffff = [subview valueForKey:@"numberOfActiveBars"];
NSLog(@"fffff=%d",fffff);
break;
}
}
for (id subview in subviews)
{
NSLog(@"antennaBar cccccc");
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]])
{
NSLog(@"antennaBar dddddd");
[(NSNumber*)[subview valueForKey:@"dataNetworkType"] intValue];
}
}
NSLog(@"antennaBar 9");
NSLog(@"12345");
id statusBaraaaa = [[UIApplication sharedApplication] valueForKey:@"statusBar"];
NSArray *children = nil;
NSLog(@"23456");
children = [[[statusBaraaaa valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSLog(@"34567");
int type = 0;
NSLog(@"45678");
for (id child in children) {
NSLog(@"56789");
if ([child isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
NSLog(@"67890");
type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
}
}
if (type == 0) {
return NO;
}else{
return YES;
}
int aaa = [[dataNetworkItemView valueForKey:@"signalStrengthBars"] intValue];
NSLog(@"aaa=%d",aaa);
return aaa;
}
@end
■Test1.h
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface Test1 : NSObject
- (int)antennaBar;
@end
■注销
(
"<_UIStatusBar: 0x14e809020: regions={\n bottomLeading = \"<_UIStatusBarRegion: 0x1d013bd00: identifier=bottomLeading, enabled=1, displayItems={(\n)}>\";\n expandedLeading = \"<_UIStatusBarRegion: 0x1d013bbc0 : identifier=expandedLeading, enabled=0, displayItems={(\n)}>\";\n expandedTrailing = \"<_UIStatusBarRegion: 0x1d013bc60: identifier=expandedTrailing, enabled=0, displayItems={(\n)}>\ ";\n leading = \"<_UIStatusBarRegion: 0x1d013b940: identifier=leading, enabled=1, displayItems={(\n <_UIStatusBarDisplayItem: 0x1d019b450: identifier=_UIStatusBarTimeItem.shortTimeDisplayIdentifier, item=<_UIStatusBarTimeItem: 0x1d046c700: identifier=_UIStatusBarTimeItem >, view=<_UIStatusBarStringView: 0x14e825ae0; frame = (14.3333 3.66667; 38.3333 18); text = '12:10'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x1d0281f40>>>\n)}>\";\n pill = \"<_UIStatusBarRegion: 0x1d013b8a0: identifier=pill, enabled=0, displayItems={(\n)}>\";\n systemUpdates = \"<_UIStatusBarRegion: 0x1d0
1
2
3
4
5
7
8
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
cccccc
cccccc
cccccc
cccccc
cccccc
cccccc
9
12345
23456
34567
45678
56789
56789
56789
56789
56789
56789
虽然通过检查状态栏视图层次结构获取信号强度在 iOS 的某些先前版本中有效,但自 iOS 11 起不再有效。
此外,依赖内部意见是(并且一直是)在应用商店审查过程中被拒绝的理由。
不支持获取蜂窝信号强度的方法。资料来源:comment on Apple Developer Forum。
唯一支持的获取 WiFi 信号强度的方法是使用 NEHotspotNetwork signalStrength 属性。
但是这个属性只适用于热点助手应用,requires a special entitlement.
您可以检索活动条的数量、可能的条数以及用户是连接到 wifi 还是蜂窝网络。 (我相信这就是 "mode" 属性/ iVar 的用途。)
我已经使用 inactive 和 activeColor 方法根据信号强度设置 wifi 和蜂窝数据的颜色,而不使用活动条的数量,因为它是视觉表示的。当然,我在越狱设备上做了一个调整,使用这个 API 没有很好地隐藏它可以让你的应用程序被拒绝。但是无论如何,请尝试使用 _UIStatusBarSignalView 来获取您需要的信息(当然仅用于测试目的)。我认为这只适用于现代状态栏/iPhone X 类型。
@interface _UIStatusBarSignalView : UIView <_UIStatusBarDisplayable> {
BOOL _smallSize;
BOOL _visible;
long long _numberOfBars;
long long _numberOfActiveBars;
long long _signalMode;
UIColor* _inactiveColor;
UIColor* _activeColor;
}
@property (assign,nonatomic) long long numberOfBars;
//@synthesize numberOfBars=_numberOfBars - In the implementation block
@property (assign,nonatomic) long long numberOfActiveBars;
/* You can use this compared to the output of numberOfBars property to get a
good idea of signal strength. */
//@synthesize numberOfActiveBars=_numberOfActiveBars - In the implementation
//block
@property (assign,nonatomic) long long signalMode;
//...(more to the interface)
@end
完整的界面可以在这里找到,我可以确认它在 iPhone X 的 iOS 12.4 上工作,即使 class 转储来自 11.1.2。
http://developer.limneos.net/?ios=11.1.2&framework=UIKit.framework&header=_UIStatusBarSignalView.h
为了获取 iphone 上的 wifi 或蜂窝信号强度, 我写了以下代码作为各种网站的参考, 但它不出现在 IF 语句中 "UIStatusBarSignalStrengthItemView" 或“_UIStatusBarCellularSignalView”。
您需要许可吗?
■开发环境
Xcode9.4.1
iPhoneX‖iOS:11.0.1
■Test1.m
#import "Test1.h"
@implementation Test1 : NSObject
- (int)antennaBar
{
NSLog(@"%@",[[[UIApplication sharedApplication] valueForKeyPath:@"statusBar"] subviews]);
NSLog(@"antennaBar 1");
NSLog(@"antennaBar 2");
// NSArray *subviews = [[[apps valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSArray *subviews = nil;
NSLog(@"antennaBar 3");
id statusBar = [[UIApplication sharedApplication] valueForKey:@"statusBar"];
NSLog(@"antennaBar 4");
if ([statusBar isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
NSLog(@"antennaBar 5");
subviews = [[[statusBar valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
} else {
NSLog(@"antennaBar 6");
subviews = [[statusBar valueForKey:@"foregroundView"] subviews];
}
NSLog(@"antennaBar 7");
NSString *dataNetworkItemView = nil;
NSLog(@"antennaBar 8");
for (id subview in subviews) {
NSLog(@"Class - %@", NSStringFromClass([subview class]));
NSLog(@"antennaBar aaaaaaa");
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
NSLog(@"antennaBar bbbbbb");
dataNetworkItemView = subview;
break;
}
if([subview isKindOfClass:[NSClassFromString(@"_UIStatusBarCellularSignalView") class]]) {
NSLog(@"antennaBar eeeeee");
dataNetworkItemView = subview;
int fffff = [subview valueForKey:@"numberOfActiveBars"];
NSLog(@"fffff=%d",fffff);
break;
}
}
for (id subview in subviews)
{
NSLog(@"antennaBar cccccc");
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]])
{
NSLog(@"antennaBar dddddd");
[(NSNumber*)[subview valueForKey:@"dataNetworkType"] intValue];
}
}
NSLog(@"antennaBar 9");
NSLog(@"12345");
id statusBaraaaa = [[UIApplication sharedApplication] valueForKey:@"statusBar"];
NSArray *children = nil;
NSLog(@"23456");
children = [[[statusBaraaaa valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSLog(@"34567");
int type = 0;
NSLog(@"45678");
for (id child in children) {
NSLog(@"56789");
if ([child isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
NSLog(@"67890");
type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
}
}
if (type == 0) {
return NO;
}else{
return YES;
}
int aaa = [[dataNetworkItemView valueForKey:@"signalStrengthBars"] intValue];
NSLog(@"aaa=%d",aaa);
return aaa;
}
@end
■Test1.h
#import <Foundation/Foundation.h>
#import "UIKit/UIKit.h"
@interface Test1 : NSObject
- (int)antennaBar;
@end
■注销
( "<_UIStatusBar: 0x14e809020: regions={\n bottomLeading = \"<_UIStatusBarRegion: 0x1d013bd00: identifier=bottomLeading, enabled=1, displayItems={(\n)}>\";\n expandedLeading = \"<_UIStatusBarRegion: 0x1d013bbc0 : identifier=expandedLeading, enabled=0, displayItems={(\n)}>\";\n expandedTrailing = \"<_UIStatusBarRegion: 0x1d013bc60: identifier=expandedTrailing, enabled=0, displayItems={(\n)}>\ ";\n leading = \"<_UIStatusBarRegion: 0x1d013b940: identifier=leading, enabled=1, displayItems={(\n <_UIStatusBarDisplayItem: 0x1d019b450: identifier=_UIStatusBarTimeItem.shortTimeDisplayIdentifier, item=<_UIStatusBarTimeItem: 0x1d046c700: identifier=_UIStatusBarTimeItem >, view=<_UIStatusBarStringView: 0x14e825ae0; frame = (14.3333 3.66667; 38.3333 18); text = '12:10'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x1d0281f40>>>\n)}>\";\n pill = \"<_UIStatusBarRegion: 0x1d013b8a0: identifier=pill, enabled=0, displayItems={(\n)}>\";\n systemUpdates = \"<_UIStatusBarRegion: 0x1d0
1
2
3
4
5
7
8
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
Class - UIView
aaaaaaa
cccccc
cccccc
cccccc
cccccc
cccccc
cccccc
9
12345
23456
34567
45678
56789
56789
56789
56789
56789
56789
虽然通过检查状态栏视图层次结构获取信号强度在 iOS 的某些先前版本中有效,但自 iOS 11 起不再有效。 此外,依赖内部意见是(并且一直是)在应用商店审查过程中被拒绝的理由。
不支持获取蜂窝信号强度的方法。资料来源:comment on Apple Developer Forum。 唯一支持的获取 WiFi 信号强度的方法是使用 NEHotspotNetwork signalStrength 属性。 但是这个属性只适用于热点助手应用,requires a special entitlement.
您可以检索活动条的数量、可能的条数以及用户是连接到 wifi 还是蜂窝网络。 (我相信这就是 "mode" 属性/ iVar 的用途。)
我已经使用 inactive 和 activeColor 方法根据信号强度设置 wifi 和蜂窝数据的颜色,而不使用活动条的数量,因为它是视觉表示的。当然,我在越狱设备上做了一个调整,使用这个 API 没有很好地隐藏它可以让你的应用程序被拒绝。但是无论如何,请尝试使用 _UIStatusBarSignalView 来获取您需要的信息(当然仅用于测试目的)。我认为这只适用于现代状态栏/iPhone X 类型。
@interface _UIStatusBarSignalView : UIView <_UIStatusBarDisplayable> {
BOOL _smallSize;
BOOL _visible;
long long _numberOfBars;
long long _numberOfActiveBars;
long long _signalMode;
UIColor* _inactiveColor;
UIColor* _activeColor;
}
@property (assign,nonatomic) long long numberOfBars;
//@synthesize numberOfBars=_numberOfBars - In the implementation block
@property (assign,nonatomic) long long numberOfActiveBars;
/* You can use this compared to the output of numberOfBars property to get a
good idea of signal strength. */
//@synthesize numberOfActiveBars=_numberOfActiveBars - In the implementation
//block
@property (assign,nonatomic) long long signalMode;
//...(more to the interface)
@end
完整的界面可以在这里找到,我可以确认它在 iPhone X 的 iOS 12.4 上工作,即使 class 转储来自 11.1.2。 http://developer.limneos.net/?ios=11.1.2&framework=UIKit.framework&header=_UIStatusBarSignalView.h