0
votes

"Allow the Home button to cancel alerts. Pressing Home while an alert is visible exits the app. It should also produce the same effect as tapping the Cancel button—that is, the alert is dismissed without performing any action. If your alert doesn’t have a Cancel button, consider implementing a cancel action in your code that runs when the Home button is pressed."

How does one affect the behavior of the home button?

Even built-in apps do not do this.

https://developer.apple.com/ios/human-interface-guidelines/ui-views/alerts/

2

2 Answers

1
votes

It doesn't mean you have to affect the behavior of the back button. It just means that, whenever the app goes into the background you should dismiss the alert as if the user had pressed the cancel button (or whatever is the equivalent on your app).

1
votes

As @Pochi said it doesn't mean that your app won't close. What they are saying is that you need to get rid of any alerts if your app enters the background. For example its possible for an Alert to be displayed, then the app closes but the Alert would still be there over the top of the users home screen. Obviously this is not ideal.

The way too intercept the home button press and do this is through the AppDelegate class.

The three methods you are looking for are:

optional func applicationWillResignActive(_ application: UIApplication)
optional func applicationDidEnterBackground(_ application: UIApplication)
optional func applicationWillTerminate(_ application: UIApplication)