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’s
applicationProtectedDataWillBecomeUnavailable:
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.
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
谷歌io开发者大会2018:AI无处不在
中国时间5月9日凌晨,谷歌一年一度的I/O开发者大会在旧金山山景城开幕。在两个小时的KeyNote演讲中,谷歌着重介绍了谷歌助手(Google Assitant)、安卓新版本Android P Beta的更新,以及一些谷歌软件(谷歌地图、谷歌新闻、谷歌摄像头)的更新,同时还谈到了谷歌在自动驾驶领域和TPU芯片研发的新进展。AI无处不在谷歌将AI作为公司的重点发展方向,在这场KeyNote演讲中,处处体现着这个特征。谷歌首席执行官Sundar Pichai首先登场,一上场,Sundar Pichai就谈了谷歌AI在不同领域的应用。比如在医疗领域,谷歌AI可以在糖尿病视网膜病变和心血管风险方面帮助诊断,还能帮助医生预测患者再次入院的可能性。又例如,通过AI与NLP技术,谷歌现在可以讲两个人同时讲话时的声音分割开来用文字显示。而且现在语言残障人士能够通过谷歌键盘(G-borad)用摩斯电码合成自己的声音。Sundar Pichai还提到了Gmail运用AI技术生成自动回复的功能。这些都是谷歌在AI领域的一些尝试,但大会的重点还是放在谷歌助手(Google Assitant)、安卓新版本And...
- 下一篇
Android中的Style、Theme详解已经发展史
版权声明:本文为sydMobile原创文章,转载请务必注明出处! https://blog.csdn.net/sydMobile/article/details/80164916 Style介绍 style就像单词意思一样,风格,这里面是属性的集合,如果页面中有许多控件的属性值相同那么就可以把这些属性抽出来放到style里面,定义也很简单,在values文件下的styles里面创建就可以了。 例如: Style的使用 这个相对来说就简单了,系统中也为我们预先定义了许多style,看了上一篇介绍的attr相信系统定义的这些style也会看懂吧。 文章最早发布于我的微信公众号 Android开发者家园 中,欢迎大家扫描下面二维码关注微信公众获取更多知识内容。 本文为sydMobile原创文章,可以随意转载,但请务必注明出处! Theme Theme和Style使用的是同一个元素标签<style>区别在与 Theme 与 Style 作用的范围不同,Theme 要求你设置到AndroidMainfest.xml的<application>或者<activity&...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS关闭SELinux安全模块
- Hadoop3单机部署,实现最简伪集群
- CentOS8编译安装MySQL8.0.19
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8安装Docker,最新的服务器搭配容器使用
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- 设置Eclipse缩进为4个空格,增强代码规范
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程