iOS

Mapwize integrations in iOS (Swift)

Integration Sample

Adding the dependency

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 items to your info.plist

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/>

Getting Permission

Colocator requires usage of Location, Bluetooth and Motion for providing enough indoor location data.

Location Permission

let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()

Bluetooth Permission

CCLocation.sharedInstance.triggerBluetoothPermissionPopUp()

Motion & Fitness Permission

CCLocation.sharedInstance.triggerMotionPermissionPopUp()

Enabling Location Gathering

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
}

Setup Mapwize Map

Import Mapwize library in your ViewController

import MapwizeUI

Configure Map UI

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)

Configure MapwizeView Delegate

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!) { }

}

Setup CCLocation

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() { }
}

Setup Location Provider

Add ILIndoorLocationProvider

let indoorLocationProvider = ILIndoorLocationProvider()

and a variable for the last location

var lastIndoorLocation: ILIndoorLocation?

Add ILIndoorLocationProviderDelegate

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!) { }
}

Display Location in Mapwize

Set IndoorLocationProvider for Mapwize

In mapwizeViewDidLoad(_ mapwizeView: MWZMapwizeView!) method from MWZMapwizeViewDelegate add

map.mapView.setIndoorLocationProvider(indoorLocationProvider!)

Start receiving updates

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)

Stop Location Updates

Unregister location listener when user exit the map screen

In viewWillDisappear(_ animated: Bool) method in the ViewController presenting the Mapwize map add

CCLocation.sharedInstance.unregisterLocationListener()