gpt4 book ai didi

ios - iPhone 来电时如何截屏

转载 作者:行者123 更新时间:2023-11-30 10:53:02 25 4
gpt4 key购买 nike

我想管理来电操作以进行屏幕截图。屏幕截图已制作,但没有我的来电屏幕。我怎样才能实现这个目标?

class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var callObserver: CXCallObserver!
var photoDelegate: UIImageView!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
callObserver = CXCallObserver()
callObserver.setDelegate(self, queue: nil) // nil queue means main thread
return true
}
}

和 CXCallObserverDelegate

extension AppDelegate: CXCallObserverDelegate {
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
if call.hasEnded == true {

}
if call.isOutgoing == true && call.hasConnected == false {
}
if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
print("Incoming \(call.uuid.description)")
imagine = UIImageView(image: UIApplication.shared.screenShot!)
}

if call.hasConnected == true && call.hasEnded == false {

}
}
}

屏幕截图

extension UIApplication {

var screenShot: UIImage? {

if let rootViewController = keyWindow?.rootViewController {
let scale = UIScreen.main.scale
let bounds = rootViewController.view.bounds
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale);
if let _ = UIGraphicsGetCurrentContext() {
rootViewController.view.drawHierarchy(in: bounds, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenshot
}
}
return nil
}
}

最佳答案

用户接到电话时显示的 CallKit UI 是 iOS 的一部分,而不是您的应用程序的一部分,接听电话后,应用程序将获得焦点,您可以进行屏幕截图。

Replaykit可以作为替代解决方案。

关于ios - iPhone 来电时如何截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54265517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com