My application can open PDF-files. So I registered it for PDF-files. When I open a PDF-file from the mail-app my application get called and the following function is called:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let rect = app.keyWindow?.rootViewController?.view.bounds
viewController.view.backgroundColor = UIColor.red
let picker = UIPickerView(frame: CGRect(x: 0, y: 100, width: (rect?.width)!, height: (rect?.height)! / 3))
picker.delegate = self
picker.dataSource = self
viewController.view.addSubview(picker)
let okButton = UIButton(frame: CGRect(x: 0, y: 100 + ((rect?.height)! / 3), width: ((rect?.width)! / 2) - 20, height: 30))
okButton.setTitle("Ok", for: .normal)
okButton.addTarget(self, action: #selector(AppDelegate.endApp), for: .touchUpInside)
viewController.view.addSubview(okButton)
app.keyWindow?.rootViewController?.present(viewController, animated: true, completion: nil)
return true
}
This works! If the user click on the ok Button I want to go back to the mail-app. How can I do this? I read, that apple don't allow you to switch between apps. But whatsApp is doing this.
I tried it with removing the viewController:
viewController.view.removeFromSuperview()
But then I only get a black screen.