Add the CCLocation and MapwizeUI pods to your Podfile
platform :ios, '9.0'
use_frameworks!
target 'YourAppTarget' do
pod 'CCLocation', '>= 2.4.0'
pod 'MapwizeUI', '~> 2.0'
end
Add the Background Modes
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
Add Permission Descriptors
<key>NSBluetoothPeripheralUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
<key>NSMotionUsageDescription</key>
<string>YOUR_TEXT_GOES_HERE</string>
For more details about these permissions in the iOS section
Add Mapwize Credentials
<key>MGLMapboxAccessToken</key>
<string>YOUR_ACCESS_TOKEN</string>
<key>MWZMapwizeApiKey</key>
<string>YOUR_API_KEY</string>
Enable Mapbox metrics
<key>MGLMapboxMetricsEnabledSettingShownInApp</key>
<true/>
Colocator requires usage of Location, Bluetooth and Motion for providing enough indoor location data.
let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
CCLocation.sharedInstance.triggerBluetoothPermissionPopUp()
CCLocation.sharedInstance.triggerMotionPermissionPopUp()
The library must be started within the func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
method of the AppDelegate
.
import CCLocation
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CCLocation.sharedInstance.start(apiKey: YOUR_APP_KEY)
return true
}
Import Mapwize library in your ViewController
import MapwizeUI
Configure and add a MapwizeView element
var map: MWZMapwizeView!
let mapFrame = view.frame
let mapwizeConfiguration = MWZMapwizeConfiguration(apiKey: YOUR_API_KEY)
let mapUIOptions = MWZUIOptions()
let mapUISettings = MWZMapwizeViewUISettings()
map = MWZMapwizeView(frame: mapFrame,
mapwizeConfiguration: mapwizeConfiguration,
mapwizeOptions: mapUIOptions,
uiSettings: mapUISettings)
view.addSubview(map)
Set MWZMapwizeViewDelegate for map
map.delegate = self
extension ViewController: MWZMapwizeViewDelegate {
func mapwizeView(_ mapwizeView: MWZMapwizeView!, shouldShowInformationButtonFor mapwizeObject: MWZObject!) -> Bool {
if (mapwizeObject is MWZPlace) {
return true
}
return false
}
func mapwizeView(_ mapwizeView: MWZMapwizeView!, shouldShowFloorControllerFor floors: [MWZFloor]!) -> Bool {
if (floors.count > 1) {
return true
}
return false
}
func mapwizeViewDidLoad(_ mapwizeView: MWZMapwizeView!) { }
func mapwizeView(_ mapwizeView: MWZMapwizeView!, didTapOnPlaceInformationButton place: MWZPlace!) { }
func mapwizeView(_ mapwizeView: MWZMapwizeView!, didTapOnPlaceListInformationButton placeList: MWZPlacelist!) { }
func mapwizeViewDidTap(onFollowWithoutLocation mapwizeView: MWZMapwizeView!) { }
func mapwizeViewDidTap(onMenu mapwizeView: MWZMapwizeView!) { }
}
Import CCLocation library
import CCLocation
Set delegate for CCLocation library
CCLocation.sharedInstance.delegate = self
extension ViewController: CCLocationDelegate {
func ccLocationDidConnect() { }
func ccLocationDidFailWithError(error: Error) { }
func didReceiveCCLocation(_ location: LocationResponse) { }
func didFailToUpdateCCLocation() { }
}
let indoorLocationProvider = ILIndoorLocationProvider()
and a variable for the last location
var lastIndoorLocation: ILIndoorLocation?
Add delegate for the IndoorLocationProvider
indoorLocationProvider?.addDelegate(self)
indoorLocationProvider?.dispatchDidStart()
extension ViewController: ILIndoorLocationProviderDelegate {
func provider(_ provider: ILIndoorLocationProvider!, didUpdate location: ILIndoorLocation!) { }
func provider(_ provider: ILIndoorLocationProvider!, didFailWithError error: Error!) { }
func providerDidStart(_ provider: ILIndoorLocationProvider!) { }
func providerDidStop(_ provider: ILIndoorLocationProvider!) { }
}
In mapwizeViewDidLoad(_ mapwizeView: MWZMapwizeView!)
method from MWZMapwizeViewDelegate
add
map.mapView.setIndoorLocationProvider(indoorLocationProvider!)
Register CCLocation for location updates
CCLocation.sharedInstance.registerLocationListener()
In didReceiveCCLocation(_ location: LocationResponse)
method from CCLocationDelegate
add
lastIndoorLocation = ILIndoorLocation(provider: indoorLocationProvider,
latitude: location.latitude,
longitude: location.longitude,
floor: 1)
indoorLocationProvider?.dispatchDidUpdate(lastIndoorLocation)
In viewWillDisappear(_ animated: Bool)
method in the ViewController
presenting the Mapwize map add
CCLocation.sharedInstance.unregisterLocationListener()