Sensitivity using SwiftUI

📘

Sensitivity support

Support for sensitivity in SwiftUI is available from version 2.1 and is a standard part of the Smartlook SDK.

When using the native rendering mode, the SDK can record sensitive data in your application.

In order to protect user privacy, you can configure Smartlook to not record sensitive data.

Smartlook attempts to hide selected sensitive UI elements automatically. It can be also instructed to hide or show particular UI components. Alternatively, using one of the wireframe rendering modes records the screen in a schematic way, showing no user data. The last possibility is to stop screen capturing altogether by using no rendering mode.

👍

Locally hidden elements

Sensitive elements are hidden locally on the device. No sensitive data is transferred to or stored in the dashboard.

View sensitivity

You can set the sensitivity of any View with the corresponding ViewModifier:

Text("Example")
    .smartlookSensitive()

If you need to control the sensitivity of View dynamically, you can set this by optional parameter:

Text("Example")
    .smartlookSensitive(true|false)

Advanced sensitivity control

Because SwiftUI does not use class hierarchy like UIKit, but dynamically generates content, the use of inheritance is irrelevant. The corresponding functions for setting sensitivity based on a class, instance, or using a protocol are unavailable for View.

However, this is not a limitation because there are other, more appropriate ways to handle similar needs in SwiftUI.

For example, suppose you have an element aggregating multiple elements and want to set all contained elements as sensitive. You can use the .smartlookSensitivity() modifier directly on the aggregating element. Sensitivity set in this way will be propagated to all contained elements.

Group {
    Text("First text")
    Text("Second text")
}
.smartlookSensitive()

Similarly, if an element needs to be completely hidden (for example, List), then we can set the appropriate sensitivity:

struct NamesListView: View {
    let names = ["John", "Alena", "Kabir"]
    
    var body: some View {
        List(names, id: \.self) { name in
            Text("\(name)")
                .padding()
        }
        .smartlookSensitive()
    }
}

Default sensitivity

Some UI elements in UIKit are default sensitive. This setting causes potentially sensitive areas to be hidden and not visible even in SwiftUI.

If a UIView descendant is used directly or indirectly in SwiftUI, its sensitivity will be propagated to the corresponding View.

📘

Some SwiftUI elements, such as TextField, perform this encapsulation in the background.

Interference with UIKit

Disabling sensitivity on a View that encapsulates a descendant of UIView with defined sensitivity does not carry over to the encapsulated UIView. To fully control the sensitivity on such a View, you must disable sensitivity on the encapsulated UIView using the UIKit API and then set the sensitivity on the View.

Enabling sensitivity on the View item that encapsulates the UIView descendant can be done at any time and always takes precedence over the settings for the encapsulated UIView.

🚧

Disabling the default sensitivity

For UITextEdit, etc. must be done outside the View, ideally in the main application's controller or another suitable place. It is strongly discouraged to do this directly in View.

For applications combining SwiftUI and large parts in UIKit, remember that disabling default sensitivity is for the entire application. This will also affect parts in UIKit.