6

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.
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115

1 Answers1

13

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

Community
  • 1
  • 1
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65
  • Ok, thanks. If this method doesn't pass Apple's static analyzer, most likely, MS Teams team just does `base64` the selector name and decodes it at runtime. – Richard Topchii Jun 04 '19 at 13:15
  • Yeah, Apple's static analyzer never raise this type of issue. I think you need to worry about apple human reviewer team – Hitesh Surani Jun 04 '19 at 13:24
  • 1
    Most likely. they hide that feature during the review and enable it remotely after the app has passed the human review. – Richard Topchii Jun 04 '19 at 13:34
  • 1
    @RichardTopchiy Exactly. Other developers including me doing the same thing if I want to hide some violation apple policy or some hidden feature of the app – Hitesh Surani Jun 04 '19 at 13:38
  • 1
    Yes, just imagine a news app (e.g. "Bloomberg") who has to comply with their rules of "not mentioning other platforms" when a large portion of Bloomberg's content is tech coverage – Richard Topchii Jun 04 '19 at 13:49