In the screensot below I have opened the App Switcher whist the sample app was running in the foreground. This can be seen by running the sample app on iPad and opening multiple windows. Only then will the task switcher show the privacy message for the app. You have to return the home screen or switch to a different app to cause the app to move to the background. The app doesn’t actually move to the background in this scenario it only becomes inactive. ![]() However, if you open the App Switcher whilst the app is in the foreground you will still see the main interface. If you run the app again, return to the home screen and then open the App Switcher you should see that the privacy message is shown in the app’s snapshot image. The fourth commit in my sample project has the changes from this step. ![]() The more modern UIAlertController seems to be presented as a normal view controller rather than a special window on top of the app. I think this may be related to the old UIAlertView class that was deprecated in iOS 9. It doesn’t seem to be necessary anymore, but I configure the windowLevel to be one higher than the alert level. It is also less likely to cause any problems with the code in the main app which might not like suddenly having a new view controller presented in its view hierarchy. This simplifies the code because we don’t have to find the most-presented view controller in order to present another view controller. Add a section to the end of the class to define an optional privacyProtectionWindow property and the methods to show/hide a window which contains our PrivacyProtectionViewController.Ī window is used to show the PrivacyProtectionViewController instead of presenting the view controller full screen on top of the app. Later I will show how to adapt the solution to work with the older application-based lifecycle prior to iOS 13.Įdit SceneDelegate.swift to add calls to hide/show the privacy protection window to the sceneWillEnterForeground(_:) and sceneDidEnterBackground(_:) methods. In order to hide the app’s main interface from the iOS App Switcher we need to show our PrivacyProtectionViewController when the scene enters the background and remove it when the scene enters the foreground. Show PrivacyProtectionViewController when Backgrounded The top frame (the slice element in the tuple returned by the method) is assigned to the frame of the privacyLabel and the bottom frame (the remainder element in the tuple) is ignored. The code in viewWillLayoutSubviews calculates the desired height for the label and uses the divided(atDistance:from:) method on CGRect to split the view controller’s view’s bounds into two frames corresponding to the top two thirds and the bottom third. Rather than vertically centre the label I preferred to have the label centred within the top two thirds of the view. I want the text size to adapt with the user’s Dynamic Type settings so configure the font for the Title1 text style and ensure it will automatically adjust if the user change’s their preferred text size. The label contains a simple multi-line message “Content hidden to protect your privacy” in a gray text color. This is initialised and added to the view when the property is first accessed. Lazy block-based initialisation is used to create a privacyLabel property. Inheriting from UITableViewController is a simple way to get the standard grouped table view background colour (which matches the appearance of Medical ID Record’s other view controllers). Open Xcode and select File->New->Project. At the time of writing, the current released version of Xcode is 11.3.1. To make use of iOS 13’s scene-based app lifecycle we need to be using at least Xcode 11. The code in this article is in Swift but I have also created an Objective-C version of the sample project with equivalent code changes. I also link to the changes for individual commits so you can view the differences on GitHub. You can use the git command line or a Git client (I use Atlassian’s SourceTree) to switch to specific commits or to examine the code changes for each step. There are separate commits for each significant step in the process. You can download a completed sample project from GitHub. You should then be able to apply the technique to your own projects. The simplest way to demonstrate the technique is to apply it to a sample iOS project. In this article I’m going to explain how to hide an app’s interface in the snapshot images shown in the App Switcher. Medical ID Record Hides Sensitive Information in the App Switcher
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |