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
| # | Change | Breaking | Who is affected |
|---|---|---|---|
| 1 | networkChanged() takes what changed | Yes | Every app |
| 2 | clearGeolocationCache() is removed | Yes | Apps that call it |
| 3 | createSmartLocationMeasurements is split into getSmartLocations and updateSmartLocations | Yes | Every app that uses Smart Locations |
| 4 | The fastMode parameter is gone; the fast search is the default | Yes | Every app that uses Smart Locations |
| 5 | Smart Locations no longer refreshes the network state on its own | Behaviour | Apps that relied on refresh: true to pick up a network change |
| 6 | Never an empty list: a failed measurement returns the cache, or the nearest locations | Behaviour | Apps that handle Smart Locations errors or empty lists |
| 7 | An expired user location is served while it is looked up again | Behaviour | Apps that call getUserLocation |
| 8 | C SDK: renamed functions, a grown configuration struct | Yes | C hosts |
| 9 | Token signature checks, faster NT fallback | Behaviour | Nobody 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:
| Event | Call |
|---|---|
| The underlying network changed (Wi-Fi ↔ cellular, a different Wi-Fi) | networkChanged(change: .switched(networkName:networkId:)) |
| The VPN connected | networkChanged(change: .vpnConnected) |
| The VPN disconnected | networkChanged(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. switchedsets the network name and id for you (SSID and BSSID), so thesetCurrentNetworkName/setCurrentNetworkIdcalls 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 asswitched. 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 asswitchedthrows that away. - After a disconnect, report
vpnDisconnectedbefore 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:
| Before | After | What it does |
|---|---|---|
refresh: false | getSmartLocations(subscriptionId:config:) | Returns the cached measurements for the current network. When nothing is cached it measures, waits and returns the result. |
refresh: true | updateSmartLocations(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
getSmartLocationseverywhere 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
updateSmartLocationsonly when the user asks for fresh results, for example a pull-to-refresh on the server list. If your app calledrefresh: trueon a timer, on launch or on every network change, replace those calls withgetSmartLocations. - The return type is unchanged (
[ClusterMetrics]), and so isrankSmartLocationMeasurements.
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:
| Config | Result | Typical duration | Before this release |
|---|---|---|---|
SmartLocationSearchConfig() — empty | Fast search: one good location, no throughput test | 1–2 seconds | was the full search |
discovery.recommendedSmartLocationSearchConfig() | Full search: five good locations, a short download per location | up to 30 seconds | was the same as the empty config |
| Either of the two with fields changed | Custom | — | — |
Translate your existing calls like this:
| Before | After |
|---|---|
config: SmartLocationSearchConfig(), fastMode: true | config: SmartLocationSearchConfig() |
config: SmartLocationSearchConfig(), fastMode: false | config: discovery.recommendedSmartLocationSearchConfig() |
config: discovery.recommendedSmartLocationSearchConfig(), fastMode: true | config: SmartLocationSearchConfig() |
config: custom, fastMode: false | Start from recommendedSmartLocationSearchConfig() and apply your changes to it |
config: custom, fastMode: true | custom, minus minNumberGoodCandidates, performHttpDownloadTest and performHttpUploadTest if you set them |
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) andperformHttpDownloadTest(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()
)
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.
| Situation | Before | After |
|---|---|---|
| Measurement fails, measurements are cached for this network | The 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 known | An error, or an empty list | The locations nearest to the user, closest first, at most maxLocationsToReturn |
| Measurement fails, nothing is cached, the user's position is unknown | An error, or an empty list | An error |
| VPN connected, nothing is cached for the last known real location | An empty list | The 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 up | An error | The 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
cancelOngoingOperationthe call fails withOperationRunnerProcessAbortedorInstanceDiscoveryProcessAborted. 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
updateSmartLocationsthe nextgetSmartLocationsreturns the same entry as before. - You can tell the distance fallback from a measurement: every entry has
distanceset andcandidatePhasePing,downloadanduploadunset. 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 categoryUnknownandsuitable: false. If your UI shows a quality rating per location, handleUnknown. - 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 location | Before | After |
|---|---|---|
| Not expired (about 10 minutes) | From the cache | From the cache (unchanged) |
Expired, inside the stale window (a further 24 hours, unless the server sends another stale-while-revalidate) | Waited for the lookup | Starts 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 fails | RealLocation returned the last known real location; Auto failed | Both return the last known real location, however old (Auto not while the VPN is reported up) |
| No real location ever seen, and the lookup fails | RealLocationNotAvailable | RealLocationNotAvailable (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.
RealLocationNotAvailableis 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. Autobehaves the same way unless you reportedvpnConnected. 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
| Before | After |
|---|---|
csdk_sdk_manager_network_changed(sdk) | csdk_sdk_manager_network_changed(sdk, CSDKNetworkChange, network_name, network_id) |
csdk_instance_discovery_clear_geolocation_cache | removed — 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 withcsdk_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_nameandcsdk_configuration_set_current_network_idset the network the device is on at start-up;csdk_sdk_manager_network_changedwithCSDKNetworkChangeSwitchedsets them on every switch. Without them the Smart Locations cache cannot tell two networks of the same ISP apart.CSDKConfiguration.conn_status_api_domainandconn_status_fallback_api_domainchoose where the connection status request is sent.NULLkeeps the previous behaviour.csdk_sdk_manager_iap,csdk_iap_process_amazon_paymentandcsdk_free_inapp_payment_responsefor 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
NtAutoDiscoverorGeoUnblockAutoDiscover, 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 aNetworkChange; VPN connects and disconnects are reported asvpnConnected/vpnDisconnected, never asswitched. - No call to
clearGeolocationCache()is left. - No call to
createSmartLocationMeasurementsis left. -
updateSmartLocationsis 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
Unknowncategory. - 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.