首页 文章 精选 留言 我的

精选列表

搜索[私有AI],共10000篇文章
优秀的个人博客,低调大师

iOS使用锁屏监听的私有API被拒 com.apple.springboard.lockcomplete

最近公司有个项目需要对锁屏进行监控以便进行一些操作,然后在更新新版本的时候,审核竟然被拒绝了。原因竟然是调用了 Apple 不允许使用的 锁屏API ,如下方法一;后来改成方法二,终于审核通过了。 如果不确定是哪个第三方使用了,这个可以cd 到项目根目录: grep -R 'com.apple.springboard.lockcomplete' * 他会检索出来,哪使用了 锁屏监听 方法一: 导入头文件和宏定义 // AppDelegate.m #import <notify.h> #define NotificationLock CFSTR("com.apple.springboard.lockcomplete") #define NotificationChange CFSTR("com.apple.springboard.lockstate") #define NotificationPwdUI CFSTR("com.apple.springboard.hasBlankedScreen") #define LOCK_SCREEN_NOTIFY @"LockScreenNotify" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 定义监听锁屏函数 // AppDelegate.m static void screenLockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { NSString *lockstate = (__bridge NSString *)name; if ([lockstate isEqualToString:(__bridge NSString *)NotificationLock]) { // 发送锁屏通知 [[NSNotificationCenter defaultCenter] postNotificationName:LOCK_SCREEN_NOTIFY object:nil]; NSLog(@"Lock screen."); } else { // 此处监听到屏幕解锁事件(锁屏也会掉用此处一次,所有锁屏事件要在上面实现) NSLog(@"Lock state changed."); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 添加监听函数 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationLock, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenLockStateChanged, NotificationChange, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 注意:该方法已被 Apple 禁止使用,上传的 App 审核会被拒绝! 方法二: 实现applicationProtectedDataWillBecomeUnavailable:方法监听锁屏 // AppDelegate.m #define LOCK_SCREEN_NOTIFY @"LockScreenNotify" - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName:LOCK_SCREEN_NOTIFY object:nil]; NSLog(@"Lock screen."); } 1 2 3 4 5 6 7 8 9 10 11 12 实现applicationProtectedDataDidBecomeAvailable:方法监听解锁 // AppDelegate.m #define UN_LOCK_SCREEN_NOTIFY @"UnLockScreenNotify" - (void) applicationProtectedDataDidBecomeAvailable:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName:UN_LOCK_SCREEN_NOTIFY object:nil]; NSLog(@"UnLock screen."); } 1 2 3 4 5 6 7 8 9 10 11 12 官网API 说明如下: When the user locks the device, the system calls the app delegate’sapplicationProtectedDataWillBecomeUnavailable:method. Data protection prevents unauthorized access to files while the device is locked. If your app references a protected file, you must remove that file reference and release any objects associated with the file when this method is called. When the user subsequently unlocks the device, you can reestablish your references to the data in the app delegate’sapplicationProtectedDataDidBecomeAvailable:method.

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码