如何在iOS中隐藏状态栏图标 [英] How to hide statusbar icons in iOS

查看:232
本文介绍了如何在iOS中隐藏状态栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的 mobilesubstrate tweak ,隐藏并显示状态栏图标,如电池或运营商或wifi信号压缩器。我见过 libstatusbar 项目,但我找不到如何隐藏iOS的图标。没有使用这个库,有没有其他方法可以做到这一点?我只想隐藏并显示默认图标

I want to create a simple mobilesubstrate tweak that hides and shows status bar icons like battery or Carrier or wifi signal indecator. I've seen libstatusbar project but i can't find out how to hide iOS's icons. Is there any other way to do this without the use of this library? I just want to hide and show the default icons

推荐答案

以下是我在调整中使用的内容:

Here is what I use in my tweak:

int itemToHide = 0;
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance] beginCoalescentBlock];
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance] _setItem:itemToHide enabled:NO];
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance] endCoalescentBlock];

唯一的问题 - iOS使用状态栏项的整数值,并且它们在不同的iOS版本上有所不同。您可以测试每个iOS版本并为每个版本存储值,但我找到了更好的方法。

Only problem - iOS uses integer values for status bar items and they're different on different iOS versions. You could test every iOS version and store values for each one of them but I found a better way.

我挂钩 SBStatusBarStateAggregator _setItem:(int) arg1 enabled:(BOOL)arg2 方法。然后我调用其中一个 SBStatusBarStateAggregator - (void)_update **** 方法。例如,假设我想找到位置图标索引。我调用 SBStatusBarStateAggregator - (void)_updateLocationItem 方法。然后它将调用hooked SBStatusBarStateAggregator _setItem:(int)arg1 enabled:(BOOL)arg2 我将存储索引。

I hook SBStatusBarStateAggregator _setItem:(int)arg1 enabled:(BOOL)arg2 method. Then I call one of the SBStatusBarStateAggregator -(void)_update**** methods. For example, let's say I want to find location icon index. I call SBStatusBarStateAggregator -(void)_updateLocationItem method. It then will call hooked SBStatusBarStateAggregator _setItem:(int)arg1 enabled:(BOOL)arg2 where I will store the index.

我还挂钩 SBStatusBarStateAggregator - (void)_notifyItemChanged:(int)arg 。此方法作为 SBStatusBarStateAggregator - (void)_update **** 调用的一部分调用。在确定状态栏图标索引时,我只是通过返回而不调用原始实现来忽略对它的调用。

I also hook SBStatusBarStateAggregator -(void)_notifyItemChanged:(int)arg. This method is called as part of SBStatusBarStateAggregator -(void)_update**** call. When determing status bar icon index I simply ignore calls to it by returning without calling original implementation.

如果你想永久隐藏某些图标,你还需要挂钩 SBStatusBarStateAggregator _setItem:(int)arg1 enabled:(BOOL)arg2 SBStatusBarStateAggregator - (void)_notifyItemChanged:(int)arg 为了忽略任何iOS尝试显示隐藏的图标。例如,每次更新时都会重新获得信号电平和数据/时间。

And if you want to permanently hide some of the icons you still need to hook SBStatusBarStateAggregator _setItem:(int)arg1 enabled:(BOOL)arg2 and SBStatusBarStateAggregator -(void)_notifyItemChanged:(int)arg in order to ignore any iOS attempts to show hidden icons. For example, signal level and data/time are reanabled every time they're updated.

这完全适用于iOS 7.在iOS 5-6 API上有所不同,但我使用的方法几乎相同。隐藏状态栏项目

That's all for iOS 7. On iOS 5-6 API is different but I use pretty much the same approach. To hide status bar item

int itemToHide = 0;
[[objc_getClass("SBStatusBarDataManager") sharedDataManager] setStatusBarItem:itemToHide enabled:NO];

我挂钩 SBStatusBarDataManager - (void)updateStatusBarItem:(int)item 确定图标索引,然后在位置图标的情况下调用 SBStatusBarDataManager - (void)_locationStatusChange

I hook SBStatusBarDataManager -(void)updateStatusBarItem:(int)item to determine icon index and then call SBStatusBarDataManager -(void)_locationStatusChange in case of location icon.

这篇关于如何在iOS中隐藏状态栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆