Parking SDK for iOS

Getting Started

This guide will show you how to use the aipark framework which helps you to use the aipark parking services. It takes just a few minutes to drop a production-ready parking layer into your application.

Contribute on GitHub

Requirements

  • iOS 10+
  • Swift 4

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

gem install cocoapods

To integrate Alamofire into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '10.0'
use_frameworks!

target '' do
    pod 'AIPARKSDK'
end

Dependencies

The following cocoa pods are required to run aipark

  • Alamofire ~> 4.0
  • SwiftyJSON >= 0

First Steps

To use the aipark SDK, import the package and initialize the aipark class

import AIPARKSDK
let aiparkcontroller = AIPARK(apikey: <yourAPIKey>)

Authorization

aipark is a location-based service. In order to use aipark, we need the current GPS position of the device. Therefore, add the following keys to the info.plist file.

Key Purpose
NSLocationWhenInUseUsageDescription Reason why GPS is used while app is in use
NSLocationAlwaysAndWhenInUseUsageDescription Reason why GPS is used in background

Note: You also need to allow location updates in the background mode. Otherwise, there will be an exception during the usage of the framework.

Request parking areas

To request parking areas, you need to specify a request object. This object contains the tile that you wish to get parking areas from.

Tiles

Tiles are predefined map areas. To visualize these tiles, you can visit this website Tiles. You can request tiles on the zoom levels 15 to 16. To convert a GPS coordinate with Latitude/Longitude into a tile, you can use a predefined method:

func getTileForCoordinates(latitude: Double, longitude: Double, zoom: Int) -> (x: Int, y: Int)

An example of a request to get parking areas is shown below. This returns a set of parking areas from the specified tiles.

let aiparkcontroller = AIPARK(apikey: )
let test = ParkingAreaRequest(tiles: [Tile(x: 35209, y: 21496)])
aiparkcontroller.getParkingAreas(request: test) { (parkingareas) in
  for entry in parkingareas {
    print(entry.name)
  }
}

Caching

When you request parking areas, they are cached automatically to minimize network traffic. If you request the same tile twice you will see an performance increase as the API response is already cached. Therefore just perform a second request with the getParkingAreas method. To keep the results up-to-date, the areas will be deleted every 15 min from the cache. If you request them again, they will be fetched from the webservice after that time limit.

Known issues

SIGABRT after start

If you see error messages like the following right after the app started the permission for the background mode is missing. To solve this go to your project in XCode and click on your project name in the left bar. Then switch to the capabilities tab and activate the ‘Background Modes’, specially the ‘Location updates’.

*** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-2245.4.104/Framework/CoreLocation/CLLocationManager.m:652
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'
Updated on November 17, 2018

Was this article helpful?

Related Articles

Bitnami