How to Prevent Apps From Being Deleted | Screen Time API

I'd like to implement prevent of deleting the app. In app I use Screen Time API with .individual type of authorisation.

I know it possible do manually in iPhone's Settings:

Settings > Screen Time > Content & Privacy Restrictions > iTunes & App Store Purchases > Deleting Apps

and then choose Don’t Allow option.

I've seen this implementation in other apps has been done programmatically.

How I can do the same?

App deletion can be prevented by setting application.denyAppRemoval to true in a ManagedSettingsStore

Example:

let store = ManagedSettingsStore()
store.application.denyAppRemoval = true

Please note that this settings will only be honored if the application is authorized via FamilyControls. See the ManagedSettings and FamilyControls for more details.