iOS 11 iPhone锁屏显示秒数自定义实现需求(非上架)
嘿,既然你是自用不上架,那咱们完全可以用一些绕开App Store审核限制的方案来实现iOS 11锁屏显示秒数的需求,我给你整理了两个靠谱的思路:
方案一:越狱环境下开发Substrate Tweak(最稳定的选择)
这是修改系统锁屏显示最直接的方式,越狱后我们可以直接Hook系统组件的代码:
- 原理:iOS 11的锁屏时间显示由
SpringBoard进程里的SBLockScreenDateViewController类负责,我们可以通过Substrate框架Hook这个类的时间更新方法,把秒数追加到原有时间里。 - 具体步骤:
- 先用unc0ver这类工具给你的iOS 11设备完成越狱
- 安装Theos开发框架,创建一个新的tweak项目,指定目标进程为
SpringBoard - 编写Hook代码,替换或增强原有的时间更新逻辑
- 示例代码片段:
#import <SpringBoard/SBLockScreenDateViewController.h> #import <Foundation/Foundation.h> %hook SBLockScreenDateViewController - (void)_updateLabel { %orig; // 先执行系统原本的更新逻辑 // 自定义时间格式,包含秒数 NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; [timeFormatter setDateFormat:@"HH:mm:ss"]; NSString *timeWithSeconds = [timeFormatter stringFromDate:[NSDate date]]; // 修改系统锁屏的时间标签文本 self.dateView.dateLabel.text = timeWithSeconds; } %end - 编译打包成
.deb文件,通过Cydia或者Filza安装到设备上,重启SpringBoard就能生效
方案二:非越狱环境下用私有API部署(无需越狱,但稳定性稍差)
如果不想越狱,也可以直接用Xcode把带私有API的应用部署到自己的设备上:
- 原理:创建一个悬浮在锁屏上方的透明窗口,用定时器每秒更新秒数显示。因为是自用,不用管App Store的审核规则,可以直接调整窗口层级突破沙盒限制。
- 具体步骤:
- 在Xcode里新建一个iOS应用项目,关闭App Sandbox(项目设置→Capabilities里关闭)
- 编写代码创建一个层级高于锁屏的透明窗口,添加显示秒数的标签
- 用定时器每秒更新标签内容
- 示例代码片段:
#import <UIKit/UIKit.h> @interface ViewController () @property (nonatomic, strong) NSTimer *secondUpdateTimer; @property (nonatomic, strong) UILabel *secondsLabel; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 创建悬浮窗口,层级设为高于状态栏,确保能显示在锁屏上 UIWindow *lockScreenOverlayWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; lockScreenOverlayWindow.windowLevel = UIWindowLevelStatusBar + 1; lockScreenOverlayWindow.backgroundColor = [UIColor clearColor]; lockScreenOverlayWindow.hidden = NO; // 创建秒数标签,调整位置到你想要的地方(比如时间下方) self.secondsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 160, [UIScreen mainScreen].bounds.size.width, 30)]; self.secondsLabel.textAlignment = NSTextAlignmentCenter; self.secondsLabel.textColor = [UIColor whiteColor]; self.secondsLabel.font = [UIFont systemFontOfSize:18]; [lockScreenOverlayWindow addSubview:self.secondsLabel]; // 启动定时器每秒更新 self.secondUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshSecondsDisplay) userInfo:nil repeats:YES]; [self refreshSecondsDisplay]; } - (void)refreshSecondsDisplay { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"ss"]; self.secondsLabel.text = [formatter stringFromDate:[NSDate date]]; // 也可以直接显示完整时间:HH:mm:ss,替换上面的格式即可 } @end - 用开发者账号(免费账号也可以,不过签名7天过期)把应用直接部署到你的iPhone上,打开应用后就能在锁屏看到秒数了
额外提醒
- 方案一的越狱tweak是最优解,完全融入系统锁屏,不会有遮挡或被系统杀死的问题
- 方案二的非越狱方法,重启设备后需要重新打开应用,而且iOS 11可能会在某些场景下限制悬浮窗口的显示,需要自己测试调整窗口位置和层级
- 因为是自用不上架,不用考虑Apple的审核规则,放心用就行
内容的提问来源于stack exchange,提问作者Déjà vu




