我想在有人给我打电话时截取屏幕截图。问题是,当我接到来电并尝试截图时,应用程序需要自己的屏幕。我怎样才能看到屏幕?(抱歉我的英文不好)
class ViewController: UIViewController {
private var callCenter = CTCallCenter()
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
callCenter.callEventHandler = { (call:CTCall!) in
switch call.callState {
case CTCallStateConnected:
print("CTCallStateConnected")
self.callConnected()
case CTCallStateDisconnected:
print("CTCallStateDisconnected")
self.callDisconnected()
case CTCallStateIncoming:
print("CTCallStateIncoming")
self.callIncoming()
default:
break
}
}
}
func callIncoming(){
captureScreen()
}
func callConnected(){
captureScreen()
}
func callDisconnected() {
captureScreen()
}
func captureScreen() {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
UIGraphicsEndImageContext()
imageView.image = image
}
}
答案 0 :(得分:4)
同意@holex - 你不能。出于安全/隐私原因,iOS故意限制应用访问彼此的数据。即使有针对此的解决方法,您的应用也可能在提交时被拒绝。