From the course: iOS Development: Security

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Clearing data before moving to the background

Clearing data before moving to the background - iOS Tutorial

From the course: iOS Development: Security

Start my 1-month free trial

Clearing data before moving to the background

- [Instructor] As recommended by Apple, sensitive information should be removed from views before moving the app to the background. If you want to find out more, you can visit this web page. All right, now let's implement this behavior in our app. I switch to the ViewController. I'm going to register the ViewController as an observer for the UI application willResignActive notification. This notification gets fired when the app is about to move to the background. I do that in the viewDidLoad method and we call NotificationCenter.default.addObserver and pass in the Notification.Name we're interested in. That is Notificatoin.Name.UIApplicationWillResignActive. The object argument is the object that sends the notification. We use nil which means that we accept this notification from any sender. The queue is the OperationQueue to which the block to be executed is added. I'm going to use the main OperationQueue since we want to perform UI-related methods. Finally, we need to implement the…

Contents