Search code examples
iosswifttermination

terminate app after opening safari - swift


I have a button in my app that opens a link via safari. There are some tasks user does in web and finally returns to app on pressing a button in browser. what I need to do is to terminate app when safari opens so that when user comes back form browser, app inits without previous data. That's how I open link:

let adrs = "mylink"
UIApplication.shared.openURL(NSURL(string: adrs) as! URL)

How can I achieve this?


Solution

  • Technically you can just exit the program (e.g., exit(0)). However, you should not do so, as iOS apps should not terminate on their own. Rather clean up your UI, e.g., remove all view controllers and create new ones.