状态栏上有运营商 信号强度 时间 电量 闹钟 这些信息。通过下面的方法可以获取到相应的信息
NSArray *statusBarSubviews = [[[[[UIApplication sharedApplication] valueForKey:@"_statusBar"] subviews] lastObject] subviews];
for (id subview in statusBarSubviews) {
/*
UIStatusBarSignalStrengthItemView //信号强度
_signalStrengthRaw
_signalStrengthBars
_enableRSSI
_showRSSI
UIStatusBarServiceItemView 运营商
_serviceString 中国电信
_crossfadeString null
_crossfadeStep 0
_maxWidth 1.797693134862316e+308
_serviceWidth 50
_crossfadeWidth 0
_contentType 0
_loopingNecessaryForString 0
_loopNowIfNecessary 0
_loopNowIfNecessary 0
_loopNowIfNecessary 0
UIStatusBarDataNetworkItemView 网络状态码
_dataNetworkType 5
_wifiStrengthRaw -62
_wifiStrengthBars 3
_wifiLinkWarning 0
_enableRSSI 0
_showRSSI 0
UIStatusBarBatteryItemView 电池标志
_capacity 95
_state 1
_batterySaverModeActive 0
_accessoryView
_cachedImageHasAccessoryImage 1
_cachedCapacity 95
_cachedAXHUDCapacity 0
_cachedImageSet
_cachedBatteryStyle 1
_cachedAXHUDStyle 0
_cachedAXHUDImage
UIStatusBarBatteryPercentItemView //电池百分比 _percentString
UIStatusBarIndicatorItemView 闹钟
UIStatusBarTimeItemView 时间
_timeString 18:02
_useCustomFadeAnimation 0
*/
NSLog(@"%@",[subview class]);
if ([subview isKindOfClass:NSClassFromString(@"UIStatusBarIndicatorItemView")])
{
unsigned int outCount =0;
// 遍历成员变量
Ivar *ivars = class_copyIvarList([subview class], &outCount);
for (int i =0; i < outCount; i++) {
Ivar ivar = ivars[i];
printf("%s\n",ivar_getName(ivar));
NSLog(@"%@",[subview valueForKey:[NSString stringWithFormat:@"%s",ivar_getName(ivar)]]);
}
}
}
网友评论