Getting started
Getting started
-
Contact 2GIS technical support to get an access key. Be sure to specify the
appId
of the application for which the key will be generated. -
Create a Container object, which will store all map entities. When creating the object, specify the path to the received
dgissdk.key
key file in one of the following ways:-
From
Bundle.main
of the application using the fromAsset() method (default way). The key must be attached to the application root:// Getting the key file let key = KeySource.fromAsset(KeyFromAsset(path: "dgissdk.key")) // Creating the Container let sdk = DGis.Container(keySource: key)
-
Specifying an absolute path to the key file using the fromFile() method:
// Getting the key file let key = Bundle.main.path(forResource: "dgissdk", ofType: "key").map { KeySource.fromFile(KeyFromFile(path: $0)) } // Creating the Container let sdk = DGis.Container(keySource: key)
-
Specifying a string for getting the key file using the fromString() method:
// Getting the key file let key = KeySource.fromString(KeyFromString(contents: "some content")) // Creating the Container let sdk = DGis.Container(keySource: key)
Important
DGis.Container
can be created in a single instance only. -
-
Additionally, you can specify logging settings (LogOptions) and HTTP client settings (HTTPOptions) such as timeout and caching.
// Logging settings. let logOptions = LogOptions(systemLevel: .info) // HTTP client settings. let httpOptions = HttpOptions.init() // Consent to personal data processing. let personalDataCollectionOptions = PersonalDataCollectionOptions(personalDataCollectionConsent: .granted) // Creating the Container. let sdk = DGis.Container( keySource: key, logOptions: logOptions, httpOptions: httpOptions, personalDataCollectionOptions: personalDataCollectionOptions )
Vendor Config
To override some SDK operation settings, a file in VendorConfig
format is used, which is passed during SDK container initialization.
-
Add the file to the bundle when building the application and create an instance of the File class.
For a file added to the root of the bundle and named
vendor-config.json
, the code will look like this:let vendorConfigFile = Bundle.main.path(forResource: "vendor-config", ofType: "jsonx").map { VendorConfig.fromFile(VendorConfigFromFile(path: $0)) }
-
Pass this variable as the
vendorConfigFile
parameter value when initializing Container:let sdk = DGis.Container( keySource: key, logOptions: logOptions, httpOptions: httpOptions, vendorConfigFile: vendorConfigFile ?? .none )
Working with offline data
Mobile SDK (the Full version) allows you to work with map, directory, and routing data offline from preloaded packages. This can be helpful when the network connection is low or missing.
To configure the offline mode:
-
Ensure that your access key contains proper rights for working with offline data. You can request access to offline data for all components (map, directory, routing) or select only the required ones.
-
Use TerritoryManager to download data files for territories where your application must work offline.
-
Configure SDK components for working with preloaded data:
- Map: create a data source and specify the required working mode.
- Directory: use the required method of creating an object directory.
- Routing: a hybrid mode is used by default. For details, see the routing documentation.