Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Exit from the app to Home Screen programmatically with gracefully exit with animation?

According to the Technical Q&A QA1561 any way of exiting the app is not recommended. The appropriate way is to allow the user to exit the app on their own, without forcing exit or aborting the app's execution.

However, the Microsoft Teams iOS App somehow manages not only to avoid the crash but gracefully exit with animation, similar to pressing the "Home" button on the device.

Video recording or programmatic exit in the MS Teams iOS app

Please note, that no home button has been pressed in the aforementioned example. The app performed animated exit programmatically

  1. Is this a documented feature of iOS? Or are the developers of MS Teams using some sort of the Private API?
  2. In any case, how can I exit an app programmatically with animation, so it wouldn't appear as a crash?

How to reproduce this behavior on your device:

  1. Download the MS Teams app
  2. Sign in
  3. Change the theme in the settings from "Dark" to "Light" or vice versa and click "Relaunch". Observe, how the app quits with animation.
like image 611
Richard Topchii Avatar asked Jun 04 '19 11:06

Richard Topchii


People also ask

How do I programmatically quit my iOS application?

An iOS app never displays a Close or Quit option. People stop using an app when they switch to another app, return to the Home screen, or put their devices in sleep mode. Never quit an iOS app programmatically.


1 Answers

Code:

   @IBAction func minimizeOrKillApp(){            
        UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
        //Comment if you want to minimise app
        Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (timer) in
            exit(0)
        }
    }

Output

Download sample code

It is not recommended and your app will be rejected😃. We all are the developers and We know to how to approve it from reviewer team

Apple developer question

like image 74
Hitesh Surani Avatar answered Oct 10 '22 21:10

Hitesh Surani