Advanced Threat Protection
Advanced Threat Protection (ATP) lets you block specific categories of unwanted content at the DNS level. You configure which categories to enable, and the SDK resolves the appropriate DNS IP to use.
Available categories
| Category | Description |
|---|---|
| Adult | Blocks adult and explicit content |
| Ads | Blocks advertising domains |
| Malware | Blocks known malware and phishing domains |
| Trackers | Blocks cross-site tracking domains |
Categories can be combined freely. Setting an empty list disables ATP.
Configuring categories
Set the desired categories on the Configuration object. This can be done at any time - for example, when the user updates their preferences.
- Swift
- Kotlin
let config = sdkManager.getConfiguration()
// Enable categories
config.setAdvancedThreatProtectionCategories(categories: [
.malware,
.trackers,
])
// Disable ATP
config.setAdvancedThreatProtectionCategories(categories: [])
// Read active categories
let active = config.getAdvancedThreatProtectionCategories()
val config = sdkManager.getConfiguration()
// Enable categories
config.setAdvancedThreatProtectionCategories(
listOf(
AdvancedThreatProtectionCategory.MALWARE,
AdvancedThreatProtectionCategory.TRACKERS,
)
)
// Disable ATP
config.setAdvancedThreatProtectionCategories(emptyList())
// Read active categories
val active = config.getAdvancedThreatProtectionCategories(
Getting the DNS IP
Once categories are configured, call getDnsIp with the user's subscription ID to retrieve the DNS IP to use.
- Swift
- Kotlin
// Configure categories
sdkManager.getConfiguration().setAdvancedThreatProtectionCategories(categories: [
.malware,
.ads,
])
// Get the DNS IP by fetching server locations
let dnsIp = try instanceDiscovery.getDnsIp(subscriptionId: subscriptionId)
// Apply DNS IP as the system DNS server
// Configure categories
sdkManager.getConfiguration().setAdvancedThreatProtectionCategories(
listOf(
AdvancedThreatProtectionCategory.MALWARE,
AdvancedThreatProtectionCategory.ADS,
)
)
// Get the DNS IP
val dnsIp = runCatching { instanceDiscovery.getDnsIp(subscriptionId) }.getOrThrow()
// Apply DNS IP as the system DNS server
Use this when you are already fetching server locations as part of your connection flow. The DNS IP is derived from that same response - no extra network request is made.
DNS IP Only
Use this when you only need the DNS IP, with no other location data required. It makes a dedicated lightweight request.
- Swift
- Kotlin
// Configure categories
sdkManager.getConfiguration().setAdvancedThreatProtectionCategories(categories: [
.malware,
.ads,
])
// Get only the DNS IP
let dnsIp = try instanceDiscovery.getDnsIpOnly(subscriptionId: subscriptionId)
// Apply DNS IP as the system DNS server
// Configure categories
sdkManager.getConfiguration().setAdvancedThreatProtectionCategories(
listOf(
AdvancedThreatProtectionCategory.MALWARE,
AdvancedThreatProtectionCategory.ADS,
)
)
// Get only the DNS IP
val dnsIp =
runCatching { instanceDiscovery.getDnsIpOnly(subscriptionId) }.getOrThrow()
// Apply DNS IP as the system DNS server
Error Handling
Fetching the DNS IP can throw an InstanceDiscoveryException in the following cases:
DNSSubnetIpInvalid- the server could not return a valid DNS address for the given subscription.DNSIPCalculationError- the selected categories could not be applied to the DNS address returned by the server.