Hello, I am using a custom UI. It can be opened normally, but the extension will be automatically closed after a while.
How to open the main app with custom buttons?
struct CaptureEx: LockedCameraCaptureExtension {
var body: some LockedCameraCaptureExtensionScene {
LockedCameraCaptureUIScene { session in
// CaptureExViewFinder(session: session)
MyUIKitView(session: session)
}
}
}
struct MyUIKitView: UIViewControllerRepresentable {
let session: LockedCameraCaptureSession
func makeUIViewController(context: Context) -> MyUiViewController {
let viewController = MyUiViewController()
return viewController
}
func updateUIViewController(_ uiViewController: MyUiViewController, context: Context) { }
}
class MyUiViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.red
// 创建按钮
let button = UIButton(type: .system)
// 设置按钮的标题
button.setTitle("点击我", for: .normal)
// 设置按钮的大小和位置
button.frame = CGRect(x: 100, y: 100, width: 200, height: 50)
// 添加点击事件处理程序
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
// 将按钮添加到视图中
self.view.addSubview(button)
}
@objc func buttonTapped() {
// 按钮点击事件的处理
self.openHost(with: URL("myapp://"))
}
}