ios - 为什么我无法获取 UIStatusBarSignalStrengthItemView?
问题描述
为了获取iphone上的wifi或蜂窝信号强度,我编写了以下代码作为各个站点的参考,但它没有出现在“UIStatusBarSignalStrengthItemView”或“_UIStatusBarCellularSignalView”的IF语句中。
你需要许可吗?
■开发环境
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
■登出输出
10'; 用户交互启用 = 否;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
类 - UIView
啊啊啊
类 - UIView
啊啊啊
类 - UIView
啊啊啊
类 - UIView
啊啊啊
类 - UIView
啊啊啊
类 - UIView
啊啊啊
cccccc
cccccc
cccccc
cccccc
cccccc
cccccc
9
12345
23456
34567
45678
56789
56789
56789
56789
56789
56789
解决方案
虽然通过检查状态栏视图层次结构在某些早期版本的 iOS 中工作来获取信号强度,但从 iOS 11 开始不再工作。此外,依赖内部视图是(并且一直是)在应用商店审查中被拒绝的理由过程。
没有支持的方式来获取蜂窝信号强度。资料来源:苹果开发者论坛评论。获取 WiFi 信号强度的唯一支持方法是使用NEHotspotNetwork signalStrength属性。但是这个属性只对热点助手应用程序可用,并且需要一个特殊的权利。
推荐阅读
- java - 我使用了 Jersey bean 验证,我已经传递了一条消息,根据一些文章,如果验证失败,该消息应该显示该消息
- android - Android 公共资源作为具有模块化结构的 Android 应用程序的库
- .net - MS Graph UserPrincipalName 与 OID 返回
- github - 引用 Github Actions 构建的工件
- rust - Rust 中的“静态不能评估析构函数”
- c# - 无法使用 SOAP 服务
- tableau-api - 通过 Tableau Server 从 Tableau Desktop 访问非公共 PostgreSQL 数据库
- r - 聚合打印列,但不将其保存到全局环境
- r - 在 R 的 data.table 中操作数据集时使用值而不是标签
- javascript - 如何使用javascript根据选择项更改值?