gpt4 book ai didi

ios - 为什么我无法获取 UIStatusBarSignalStrengthItemView?

转载 作者:行者123 更新时间:2023-11-28 20:56:58 29 4
gpt4 key购买 nike

为了获取iphone上的wifi或cellular信号强度, 我写了以下代码作为各种网站的引用,但它不出现在 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: 0x1d046c 700:标识符=_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

类 - UIView

啊啊啊啊

类 - UIView

啊啊啊啊

类 - UIView

啊啊啊啊

类 - UIView

啊啊啊啊

类 - UIView

啊啊啊啊

类 - UIView

啊啊啊啊

中秋节

中秋节

中秋节

中秋节

中秋节

中秋节

9

12345

23456

34567

45678

56789

56789

56789

56789

56789

56789

最佳答案

虽然通过检查状态栏 View 层次结构获取信号强度在某些早期版本的 iOS 中有效,但从 iOS 11 开始不再有效。此外,依赖内部意见是(并且一直是)在应用商店审查过程中被拒绝的理由。

没有支持的方法来获取蜂窝信号强度。来源:comment on Apple Developer Forum .获得 WiFi 信号强度的唯一支持方法是使用 NEHotspotNetwork signalStrength属性(property)。但此属性仅适用于热点助手应用程序,并且requires a special entitlement .

关于ios - 为什么我无法获取 UIStatusBarSignalStrengthItemView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373873/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com