主要记录 iOS 14 中 IOSurfaceCreate 返回 nil 的问题
现象
iOS 12/ iOS 13 调用 IOSurfaceCreate 能正常返回非空内容,但是在 iOS 14 返回了 nil
tl;dr
因为我的项目中的 entitlements 权限不够,所以导致的问题。
最后补充了需要权限的 entitlements文件。
p.s. 这个配置使用 Springboard 直接导出的,权限肯定有冗余。
解决过程
- 
在 iOS12/13 调用
IOSurfaceCreate发现能正常返回,但是 iOS14 返回空。 - 
猜测可能是
IOSurfaceCreate的参数properties有问题,导致的返回空,更改了几种参数组合依旧返回空。 - 
在 Github 中搜索各路大神写的
IOSurfaceCreate方法,发现我的 entitlements 跟大家的不太一样,猜测可能是权限不够导致的问题。 - 
使用了 Github 上的 entitlements 但还是返回空,想了想 Springboard/backboardd 应该也会用到
IOSurfaceCreate于是写了个简单的 Tweak ,在 Springboard 中调用了一下,发现返回值正常,于是使用ldid导出了 Springboard 的权限文件。 - 
直接使用导出的配置文件会有下面的两个问题,移除了这两个 Key 就不会闪退了。
 
key "com.apple.private.xpc.launchd.app-server"
会导致进程闪退,具体输出:
*** Assertion failure in +[UIScreen mainScreen], UIScreen.m:660
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:'returning nil screen from mainScreen is not allowed!'
*** First throw call stack:
(0x1aaf599d8 0x1bf2dcb54 0x1aae6850c 0x1ac162878 0x1ad3e5148 0x10286934c 0x1aabb1568)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
key "seatbelt-profiles" 会导致 kill: 9
- 
使用直接从 Springboard 导出的权限文件调用
IOMobileFramebufferGetLayerDefaultSurface会返回-536870207正常应该是 0。 Google 搜了一下,在 stackoverflow 发现可能还是少了链接中的权限,搜了一下在我之前导出的 backboardd 权限中有这个权限,把这个权限单独加入到 Springboard 的权限中问题解决! - 
重新运行程序问题解决。