Data Management¶
The Data Manager is responsible for getting updated information from Pointr Cloud, such as maps, Points of Interest, geofences and so on.
The data manager object can be accessed directly through the Pointr instance by using the getDataManager method.
By default, the data manager checks for new data if 15 minutes or more have passed since the last check in order to guarantee that the SDK always has the latest data from Pointr Cloud. This operation is very lightweight and it just compares the current data version on the SDK with the one on Pointr Cloud. When the data version on Pointr Cloud is higher, it then starts downloading the new data.
It is possible to configure how often the data is checked using dataCacheMaxAgeSeconds, either using the normal configuration methods or using the MutableDataManagerConfiguration class.
On a fresh install, the SDK immediately checks the Pointr Cloud data. The first check is mandatory and Pointr SDK will refuse to run if it fails to connect to the server at least once after a fresh install.
The Data Manager is automatically called to load the maps when using Pointr’s SDK provided Map Widget, but if you are using a custom map widget, you will need to ensure the proper data is loaded manually.
If you want to get notified by data management events, you should add a listener to the data manager object. Your listener must conform to the DataManager.Listener interface that defines all the necessary callbacks.
Warning
When there is a data update from DataManager while the Map Widget is open, the data will only get reflected on the map on the next use of the Map Widget.
Callbacks¶
To be notified of when the SDK starts and finishes checking the Pointr Cloud data, you should implement the following callbacks: NOTE: Make sure to check isOnlineData = true
func onDataManagerStartDataManagementForSite(site: PTRSite,
isOnlineData: Bool);
func onDataManagerCompleteAllForSite(site: PTRSite,
isSuccessful: Bool,
isOnlineData: Bool,
errorMessages: Dictionary);
fun onDataManagerStartDataManagementForSite(site: Site,
isOnlineData: Boolean)
fun onDataManagerCompleteAllForSite(
site: Site,
isSuccessful: Boolean,
isOnlineData: Boolean,
errors: List<ErrorMessage?>?
)
Forcing Downloads¶
In case you want to force the SDK to check the Pointr Cloud data, you can use the following method with “shouldRespectCachePolicy” set to “false”, so that data manager does the check regardless of the 15 minutes:
func loadData(forSite: Int32, shouldRespectCachePolicy: Bool);
fun loadDataForSite(site: Site, shouldRespectCachePolicy: Boolean)
PointrContent.zip¶
The first time the SDK runs, it takes information from the file PointrContent.zip, this file is signed when it is generated and shouldn’t be modified. If different contents are needed on the file it should be changed using Pointr Cloud Dashboard, where there are extensive options to enable or disable content before generating a new .zip file. The file is not needed to update content, there is no need to even change the configuration of the file. Whatever is needed will be downloaded from Pointr Cloud when a connection is made. The content downloaded will come straight from the database, there is no need to generate a new PointrContent.zip file with new content.
Updating data in Pointr Cloud¶
To update data on Pointr Cloud and get it downloaded by the DataManager it is needed two steps, one step is editing the data as needed, and the second step is “Publishing” the data. Any data changed need to be “Published” before the Data Manager downloads it. On Pointr Cloud section of this documentation there are more details about this.
Loading data for Custom Map Widget¶
When you are working with a custom map widget instead of using the default one from the SDK, you will need to load it manually.
- First thing is ensure Pointr is
RUNNING
, if Pointr main singleton class is notRUNNING
this won’t work. - Request the data with the Data Manager, using the “loadDataForSite” method.
- Make sure the data is loaded, there are two ways to do this:
- You can use a callback,
onDataManagerCompleteAllForSite
works,onDataManagerReadyForSite
also works, the difference is that being “Ready” doesn’t necessarily mean the lastest data was downloaded, only that there is “some” data ready.
- You can use a callback,
- Load the map using your custom widget.
extension CustomMapViewController: PTRDataManagerDelegate {
func customWidgetLoadContentForSite(_ site: PTRSite) {
// If you're using your own maps,
// make sure the site's data is loaded by calling the following:
let dataManager = Pointr.shared.dataManager
// Listen to data updates.
// You can also listen to each manager individually, like `PTRPoiManager`,
// by doing `Pointr.shared.poiManager?.addListener(self)`
// We recommend listening to the managers even after loading the data, to make sure
// none of the data changes are missed.
dataManager?.addListener(self)
// Load the data for the site
let forceDownload = false // True to force version check which will make sure the content is up to date with Pointr Cloud
dataManager?.loadData(forSite: site.internalIdentifier, shouldRespectCachePolicy: !forceDownload)
}
// We are here implementing a method from PTRDataManagerDelegate
func onDataManagerReady(for site: PTRSite) {
// This is called when data is ready for this site.
// This does not mean it is the latest data available on Pointr Cloud.
// It can be the current offline data just made available.
}
// We are here implementing a method from PTRDataManagerDelegate
func onDataManagerStartDataManagement(for site: PTRSite, dataFromOnline isOnlineData: Bool) {
// Triggered when the site's data begins loading
if isOnlineData {
// You can use this callback to update your UI
// like displaying a loading spinner.
}
}
// We are here implementing a method from PTRDataManagerDelegate
func onDataManagerCompleteAll(for site: PTRSite, isSuccessful: Bool, dataFromOnline isOnlineData: Bool, errorMessages: [NSNumber : String]) {
// Triggered when all types of data (pois, graph, walls, etc) finished loading for the site.
// All data is ready
if isSuccessful {
// To make sure loading was successful
}
if isOnlineData {
// To make sure it's the latest data available on Pointr Cloud.
}
}
}