Traffic iOS
Setup
In your project, add the following lines to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git' # Default Cocoapods URL
source 'https://github.com/hove-io/Podspecs.git' # Traffic podspec URL
target 'YOUR_PROJECT_SCHEME' do
pod 'TrafficSDK', '3.7.2' # Traffic Pod definition
end
# Required for XCFramework
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
Using your CLI, run pod install
in your project directory.
Implementation
Warning
Make sure to read the modules configuration section before proceeding
This module is set up by calling Traffic.shared.initialize()
method which takes the following parameters:
Name | Required | Description | Type | Example |
---|---|---|---|---|
coverage |
Navitia coverage | String |
fr-idf |
|
env |
Navitia environment | String |
PROD |
|
alertCredentials |
Kronos alert subscription credentials | TrafficAlertSubscriptionCredentials |
- | |
colors |
Define the custom colors | TrafficColorsConfiguration |
- | |
fonts |
Use custom fonts | TrafficFontsConfiguration |
- | |
lineResources |
List of transport lines resource IDs | [LineResource] |
- | |
modeResources |
List of transport modes resource IDs | [ModeResource] |
- | |
transportCategories |
List of supported transport modes | [TransportCategory] |
- | |
networkResources |
List of network resource IDs | [NetworkResource] |
- | |
features |
Enable/disable some features | TrafficFeaturesConfiguration |
- |
You can also call the initialize()
method with the global JSON configuration file added to your application bundle:
Name | Required | Description | Type | Example |
---|---|---|---|---|
configurationJsonFile |
Global configuration JSON file name | String |
configuration.json |
Example
do {
let transportCategories = [TransportCategory(
modules: ["traffic"],
iconRes: "ic_section_mode_metro",
nameRes: "metro",
selected: true,
modes: [TransportCategoryMode(
physical: TransportPhysicalMode(
id: "physical_mode:Metro",
nameRes: "metro"
),
commercial: TransportCommercialMode(
id: "commercial_mode:Metro",
name: "Metro"
)
)],
firstSectionModes: ["walking"],
lastSectionModes: ["walking"]
)]
let trafficColorsConfiguration = TrafficColorsConfiguration(
primaryColor: "#88819f",
secondaryColor: "#8faa96"
)
try Traffic.shared.initialize(
coverage: "fr-idf",
token: "your_token",
env: "PROD",
colors: trafficColorsConfiguration,
transportCategories: transportCategories
)
} catch {
Logger.error("%@", String(
format: "Traffic SDK cannot be initialized! %@",
error.localizedDescription
))
}
Alert subscription
To enable the alert subscription feature, the following instructions are required:
- Add the environment configuration
- Pass the Kronos API credentials to the initialization method
- Set the firebase token
Traffic.shared.firebaseToken = "token"
once received from the Firebase API at runtime
Traffic alert subscription credentials
Name | Required | Description | Type |
---|---|---|---|
username |
Kronos authentication username | String |
|
password |
Kronos authentication password | String |
Events tracking
In order to receive the list of generated events within Traffic module, you have to assign the instance of the tracker to the Traffic module instance as follows and implement the required methods:
Launching
This module has a single entry point. The parameter showBack
handles the back button visibility on the first screen.
guard let trafficViewController = Traffic.shared.rootViewController else {
return nil
}
trafficViewController.showBack = false // Hide back button embedded in the first screen
If you want to use the rootViewController
as a ChildViewController
of your ViewController
, you should embed it in an NavigationController
.