Skip to main content

Migrating from 34.1.0

This guide takes an app from SDK 34.1.0 to the release that follows it. It covers every change in that release that needs a code change or changes what your app observes, in the order you should work through them. The full list of changes is in the CHANGELOG.

Examples are in Swift. Kotlin, C#, Go and Dart use the same names in their own casing; C names are given separately.

At a glance​

#ChangeBreakingWho is affected
1networkChanged() takes what changedYesEvery app
2clearGeolocationCache() is removedYesApps that call it
3createSmartLocationMeasurements is split into getSmartLocations and updateSmartLocationsYesEvery app that uses Smart Locations
4The fastMode parameter is gone; the fast search is the defaultYesEvery app that uses Smart Locations
5Smart Locations no longer refreshes the network state on its ownBehaviourApps that relied on refresh: true to pick up a network change
6Never an empty list: a failed measurement returns the cache, or the nearest locationsBehaviourApps that handle Smart Locations errors or empty lists
7An expired user location is served while it is looked up againBehaviourApps that call getUserLocation
8C SDK: renamed functions, a grown configuration structYesC hosts
9Token signature checks, faster NT fallbackBehaviourNobody has to act

Do 1 first. Changes 3–7 assume the SDK is told about every network change and every VPN connect and disconnect — after this release nothing else keeps that state current.


1. networkChanged() takes what changed​

SdkManager.networkChanged() used to take no argument and treat every call as a change of network. It now takes a NetworkChange:

EventCall
The underlying network changed (Wi-Fi ↔ cellular, a different Wi-Fi)networkChanged(change: .switched(networkName:networkId:))
The VPN connectednetworkChanged(change: .vpnConnected)
The VPN disconnectednetworkChanged(change: .vpnDisconnected)
// Before
sdkManager.getConfiguration().setCurrentNetworkName(name: "Starbucks")
sdkManager.getConfiguration().setCurrentNetworkId(name: "aa:bb:cc:dd:ee:ff")
sdkManager.networkChanged()

// After
sdkManager.networkChanged(change: .switched(networkName: "Starbucks", networkId: "aa:bb:cc:dd:ee:ff"))

What to change:

  • Replace every networkChanged() call with the variant that matches the event.
  • switched sets the network name and id for you (SSID and BSSID), so the setCurrentNetworkName / setCurrentNetworkId calls before it can go. Pass empty strings on cellular or when you do not know them.
  • Report VPN connects and disconnects as vpnConnected / vpnDisconnected, never as switched. A VPN toggle does not move the device, so the SDK keeps the real location cached and the next lookup answers from the cache (about 40 ms) instead of probing the network (0.8–4 seconds). Reporting it as switched throws that away.
  • After a disconnect, report vpnDisconnected before you request anything that measures.

Details: User location and connection status.

2. clearGeolocationCache() is removed​

InstanceDiscovery.clearGeolocationCache() is no longer exported. Whatever made you call it is one of the three events above — report it with networkChanged(change:) instead. switched clears the cached geolocation; vpnConnected and vpnDisconnected keep the real location.

// Before
try sdkManager.instanceDiscovery().clearGeolocationCache()

// After
sdkManager.networkChanged(change: .switched(networkName: ssid, networkId: bssid))

3. Smart Locations: two methods instead of one​

createSmartLocationMeasurements(subscriptionId:refresh:config:fastMode:) is removed. The refresh flag became the choice between two methods:

BeforeAfterWhat it does
refresh: falsegetSmartLocations(subscriptionId:config:)Returns the cached measurements for the current network. When nothing is cached it measures, waits and returns the result.
refresh: trueupdateSmartLocations(subscriptionId:config:)Always measures and replaces the cached entry.
// Before
let metrics = try discovery.createSmartLocationMeasurements(
subscriptionId: id, refresh: false, config: SmartLocationSearchConfig(), fastMode: true
)

// After
let metrics = try discovery.getSmartLocations(subscriptionId: id, config: SmartLocationSearchConfig())

What to change:

  • Use getSmartLocations everywhere you need Smart Locations — on launch, before showing the server list, before "connect to the fastest location". You do not need to check the cache first: it fills it when it is empty.
  • Call updateSmartLocations only when the user asks for fresh results, for example a pull-to-refresh on the server list. If your app called refresh: true on a timer, on launch or on every network change, replace those calls with getSmartLocations.
  • The return type is unchanged ([ClusterMetrics]), and so is rankSmartLocationMeasurements.

4. Smart Locations: the fast search is the default​

The fastMode parameter is gone. What it selected is now decided by the config you pass, and the default changed:

ConfigResultTypical durationBefore this release
SmartLocationSearchConfig() — emptyFast search: one good location, no throughput test1–2 secondswas the full search
discovery.recommendedSmartLocationSearchConfig()Full search: five good locations, a short download per locationup to 30 secondswas the same as the empty config
Either of the two with fields changedCustom——

Translate your existing calls like this:

BeforeAfter
config: SmartLocationSearchConfig(), fastMode: trueconfig: SmartLocationSearchConfig()
config: SmartLocationSearchConfig(), fastMode: falseconfig: discovery.recommendedSmartLocationSearchConfig()
config: discovery.recommendedSmartLocationSearchConfig(), fastMode: trueconfig: SmartLocationSearchConfig()
config: custom, fastMode: falseStart from recommendedSmartLocationSearchConfig() and apply your changes to it
config: custom, fastMode: truecustom, minus minNumberGoodCandidates, performHttpDownloadTest and performHttpUploadTest if you set them
danger

Check every place you pass an empty or partly filled SmartLocationSearchConfig without fastMode: true. It compiles after you remove the fastMode argument, but it now runs the fast search. A location list built from it is ranked on latency alone, from a search that stopped at the first good location. Pass recommendedSmartLocationSearchConfig() wherever the user picks from a list.

Three more things about the record:

  • An unset field takes the fast value, not the recommended one. The two searches differ in exactly two fields: minNumberGoodCandidates (1 fast, 5 recommended) and performHttpDownloadTest (off fast, on recommended). For every other field, unset and recommended are the same.
  • Every field you set is the value the run uses. There is no switch that overrides other fields any more.
  • fastSmartLocationSearchConfig() is new. It returns the fast search with every field filled in, for when you want to read or display the values. It behaves exactly like the empty config.

A typical app ends up with two calls:

// Connect path: cached result, or a fast search if there is none.
let metrics = try discovery.getSmartLocations(subscriptionId: id, config: SmartLocationSearchConfig())

// Pull-to-refresh on the server list: the full search, replacing the cached entry.
let metrics = try discovery.updateSmartLocations(
subscriptionId: id,
config: discovery.recommendedSmartLocationSearchConfig()
)
info

The cache holds one entry per network and does not remember which search produced it. After a fast search has filled it, getSmartLocations returns that entry even when you pass the recommended config. The full list replaces it when the user refreshes, through updateSmartLocations.

Details: Smart Locations.

5. Smart Locations no longer refreshes your network state​

createSmartLocationMeasurements(refresh: true) used to clear the SDK's cached geolocation and fetch the connection status again before every measurement, and a cache miss forced the same fetch. Neither getSmartLocations nor updateSmartLocations does that. They read the user's location from the cache and ask the network only when nothing valid is cached.

This removes a network round trip that could be slow, or hang, in front of every measurement. It also means the SDK now relies entirely on what your app reports:

  • If your app used a Smart Locations refresh to pick up a network change, call networkChanged(change:) instead (change 1).
  • A network change you do not report means measurements are stored under the previous network until the cached location has expired (about 10 minutes) and been looked up again.
  • A VPN connect you do not report means the SDK may measure through the tunnel. An app that has never reported a VPN state is treated as not connected. Never start a measurement while the VPN is connected or connecting.

Smart Locations also never waits for a location lookup. In rare cases — a slow lookup right after a network switch, a VPN connect that was not reported, a move while connected — a list is therefore measured or read under a location that is not the device's. Offer a pull-to-refresh wherever you show Smart Locations: updateSmartLocations measures again and replaces the entry. See When the list looks wrong.

6. Smart Locations: what a failed measurement returns​

A measurement fails when it returns an error or when no location answered at all. The second case used to come back as an empty list.

SituationBeforeAfter
Measurement fails, measurements are cached for this networkThe cached list (on an error), or an empty list (when nothing answered)The cached list, unchanged
Measurement fails, nothing is cached, the user's position is knownAn error, or an empty listThe locations nearest to the user, closest first, at most maxLocationsToReturn
Measurement fails, nothing is cached, the user's position is unknownAn error, or an empty listAn error
VPN connected, nothing is cached for the last known real locationAn empty listThe locations nearest to the last known real location; an error (RealLocationNotAvailable) if the SDK has never seen one
The user's location cannot be looked upAn errorThe list cached for the last known real location, else the locations nearest to it; nothing is measured. An error only if the SDK has never seen a real location

What this means for your code:

  • Smart Locations never returns an empty list any more. Every call ends in measurements, cached measurements, the nearest locations by distance, or an error. Code that treated an empty result as "no Smart Locations yet" will not see it again; handle the error instead.
  • A cancelled measurement always ends in the abort error. After cancelOngoingOperation the call fails with OperationRunnerProcessAborted or InstanceDiscoveryProcessAborted. It used to return the cached list as a success when there was one; it never returns a fallback now.
  • A failed measurement never changes the cache. After a failed updateSmartLocations the next getSmartLocations returns the same entry as before.
  • You can tell the distance fallback from a measurement: every entry has distance set and candidatePhasePing, download and upload unset. It is not cached, so the next call measures again.
  • You can pass the distance fallback to rankSmartLocationMeasurements. The entries come back nearest first, with category Unknown and suitable: false. If your UI shows a quality rating per location, handle Unknown.
  • Error handling that existed only to show a fallback list when Smart Locations failed can usually go: use what the SDK returns. Keep handling the remaining error, and InstanceDiscoveryProcessAlreadyRunning.
  • While the VPN is connected nothing is measured, as before. Both methods return the cached entry for the user's last known real location, and with nothing cached the distance fallback from that location.

7. User location: served while it is refreshed​

getUserLocation no longer makes the caller wait for the server once a location is cached.

Cached real locationBeforeAfter
Not expired (about 10 minutes)From the cacheFrom the cache (unchanged)
Expired, inside the stale window (a further 24 hours, unless the server sends another stale-while-revalidate)Waited for the lookupStarts a lookup, waits up to 1 second, returns the new location if it arrived and otherwise the expired one. The lookup finishes in the background.
Past the stale window, and the lookup failsRealLocation returned the last known real location; Auto failedBoth return the last known real location, however old (Auto not while the VPN is reported up)
No real location ever seen, and the lookup failsRealLocationNotAvailableRealLocationNotAvailable (unchanged)

What this means for your code:

  • A location you get back can be old when the server is slow or unreachable: up to a day while it is being refreshed, and older still when the lookup keeps failing. If you show the user's location, the next call returns the refreshed one as soon as there is one.
  • No new error to handle. RealLocationNotAvailable is thrown only when the SDK has never seen a real location, as before.
  • The same applies after networkChanged(switched): the previous network's location is served for up to a second while the new one is looked up.
  • Auto behaves the same way unless you reported vpnConnected. While the VPN is reported up it asks the server for the VPN location instead.
  • networkChanged(vpnDisconnected) never makes the next lookup wait without a limit. If the server had reported the device off the VPN during the session, that location is treated as expired and goes through the 1-second path above.

Details: User location and connection status.

8. C SDK​

Rebuild against the new header and binary together: CSDKConfiguration has grown, so an old header with a new binary (or the reverse) reads the struct wrongly.

Renamed and removed functions

BeforeAfter
csdk_sdk_manager_network_changed(sdk)csdk_sdk_manager_network_changed(sdk, CSDKNetworkChange, network_name, network_id)
csdk_instance_discovery_clear_geolocation_cacheremoved — use csdk_sdk_manager_network_changed
csdk_instance_discovery_create_smart_location_measurements(api, subscription_id, false, config, fast_mode, &list)csdk_instance_discovery_get_smart_locations(api, subscription_id, config, &list)
csdk_instance_discovery_create_smart_location_measurements(api, subscription_id, true, config, fast_mode, &list)csdk_instance_discovery_update_smart_locations(api, subscription_id, config, &list)

Smart Locations configuration

  • CSDKSmartLocationSearchConfig cfg = {0}; is now the fast search. It used to be the full one.
  • For the full search, call csdk_instance_discovery_recommended_smart_location_search_config(api, &config) and release the result with csdk_free_smart_location_search_config.
  • csdk_instance_discovery_fast_smart_location_search_config(api, &config) is new and returns the fast search with every field filled in. Release it the same way.
CSDKClusterMetricsList* list = NULL;

// Connect path: the cache, or a fast search when it is empty.
CSDKSmartLocationSearchConfig fast = {0};
csdk_instance_discovery_get_smart_locations(api, subscription_id, &fast, &list);

// User asked for fresh results: the full search.
CSDKSmartLocationSearchConfig* full = NULL;
if (csdk_instance_discovery_recommended_smart_location_search_config(api, &full) == CSDKResultCodeOK) {
csdk_instance_discovery_update_smart_locations(api, subscription_id, full, &list);
csdk_free_smart_location_search_config(full);
}

New, optional

  • csdk_configuration_set_current_network_name and csdk_configuration_set_current_network_id set the network the device is on at start-up; csdk_sdk_manager_network_changed with CSDKNetworkChangeSwitched sets them on every switch. Without them the Smart Locations cache cannot tell two networks of the same ISP apart.
  • CSDKConfiguration.conn_status_api_domain and conn_status_fallback_api_domain choose where the connection status request is sent. NULL keeps the previous behaviour.
  • csdk_sdk_manager_iap, csdk_iap_process_amazon_payment and csdk_free_inapp_payment_response for Amazon Appstore payments.

9. Changes that need no code​

  • Token signatures are no longer checked on the client. The SDK no longer verifies the signature of subscription, connection and Dedicated IP tokens before using them; the backends that receive them still do. A token is no longer dropped because the signing keys could not be downloaded. It is still dropped when it has expired or is about to.
  • NT takes over faster on blocked networks. With NtAutoDiscover or GeoUnblockAutoDiscover, a direct request that times out falls back to NT at once instead of being retried twice, and NT is only enabled for all traffic after a short check has confirmed that the direct path is blocked.
  • Amazon Appstore in-app payments are available through InAppPayments.processAmazonPayment.

Checklist​

  • Every networkChanged() call passes a NetworkChange; VPN connects and disconnects are reported as vpnConnected / vpnDisconnected, never as switched.
  • No call to clearGeolocationCache() is left.
  • No call to createSmartLocationMeasurements is left.
  • updateSmartLocations is only called when the user asks for fresh results.
  • Every Smart Locations call that feeds a list the user picks from passes recommendedSmartLocationSearchConfig().
  • Nothing relies on a Smart Locations call to notice a network change.
  • Wherever Smart Locations are shown, the user can refresh them (pull-to-refresh → updateSmartLocations).
  • The UI handles a Smart Locations result without ping values, and the Unknown category.
  • Nothing waits for an empty Smart Locations list; the error path is handled instead.
  • C hosts: header and binary were updated together.

Then work through the measurement integration checklist once; its rules have not changed, but several of them are now the only thing keeping the SDK's network state correct.