Quickstart step 3 : iOS minimum code
Here are the steps required for a minimum integration of the Veery Geo-predictive SDK inside your IOS application.
Prerequisites
You should have requested your Developer API Key and received it in the following format:
YOURCOMPANY ACCESS KEY | Where to use in Xcode | Value (example) |
---|---|---|
CLIENT_ID | info.plist | 00000000-1234-abcd-efbh-1234567890ab |
API_KEY | info.plist | abcdef12-0123-4567-890a-bcdef1234567 |
API_SECRET | ViewController.swift -> veery.setApiKeySecret(..) | SuPeRScrET12345789GhJ |
These will be used in the next steps of the Veery integration.
Podfile
If you have already installed Pod :
-
Open your Podfile
-
Add the following lines
source 'https://github.com/roofstreet/cocoa.repo.git' target 'yourApp' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks ! # Pods for yourApp # You should use always the last version of Veery. pod 'Veery', 'X.Y.Z' end
Note : "X.Y.Z" should be replaced by the latest ios release.
If you are adding more than one Pod you must add the following in the top of the Podfile
source 'https://github.com/CocoaPods/Specs.git'
- Close your Xcode and in the console run
$ pod update
to download Veery.
Otherwise you should install pod in your Xcode project directory.
1. Run
$ pod init $ pod install
in your project directory using a console.
2. Open your Xcode project directory and lunch yourApp.xcworkspace
3. Execute the cited instruction above.
For more information see cocoapod.org.
PS :
If you never insalled Cocoapod you should intall it with the following
$ sudo gem install cocoapods
Activate Background Modes
- Select the project from the Project Navigator
- Select the app target.
- Select the Capabilities
- Turn on the Background Modes
- Check the Location updates and the Remote notifications modes.
Activate Push Notifications
- Select the project from the Project Navigator
- Select the app target.
- Select the Capabilities
- Turn on the Push Notifications
Info.plist
In your info.plist file you should add the following (using the credentials received from your API KEY registration).
Key | Type | Value |
---|---|---|
VeeryApiKey | String | abcdef12-0123-4567-890a-bcdef1234567 |
VeeryClientID | String | 00000000-1234-abcd-efbh-1234567890ab |
VeeryEnvir | String | sandbox |
For using Location updates you should add the following in your Info.plist.
Key | Type | Value |
---|---|---|
Privacy - Location Always Usage Description | String | Explain in few word the reason for what you are using the location |
Privacy - Location When In Use Usage Description | String | Explain in few word the reason for what you are using the location |
Privacy - Location Always and When In Use Usage Description | String | Explain in few word the reason for what you are using the location |
The environment should be "sandbox" unless you have received the agreement from Roofstreet to use a production platform.
AppDelegate
In your AppDelegate.swift add the following :
-
Import Veery SDK
import Veery
-
Create a Veery Object
import Veery @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? // TODO : create the veery object let veery = Veery() //.... //.... }
-
Connect to Veery in function application with didFinishLaunchingWithOptions
import Veery @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? // TODO : create the veery object let veery = Veery() func application(_ application : UIApllication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool{ //Override point for customization after application launch. // TODO : connect to veery veery.serviceConnect() return true } //.... //.... }
Remote Notifications
-
Registration
In your AppDelegate.swift add this function
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){ // Let Veery know the Device Token veery.setAPNSToken(token: deviceToken) }
-
DidReceiveRemoteNotification
After the function above add the didReceiveRemoteNotification function
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> ()) -> Void { // If veery can handle the notification, just return if (veery.apnsMessageHandler(userInfo)){return } // Veery did not recognize the notification so it comes from another framework // Your own Handle code here }
ViewController
The following is required in the ViewController of your Application:
- Implement the Veery Delegate for triggers the events
- Set the API Key Secret
- Activate the required functionalities (see ) (foreground geolocation, background geolocation, geoprofiling, predictive geolocation)
Include the library and create the veery object
In your ViewController.swift, add the following
import Foundation import UIKit import Veery class ViewController: UIViewController, VeeryDelegate {// Implement Veery Delegate // TODO : Inside the principal class (!!not inside a function) let veery = Veery() //..... }
viewDidLoad : Init the veery.delegate and declare the API Key Secret
In the viewDidLoad function add the following :
import Foundation import UIKit import Veery class ViewController: UIViewController, VeeryDelegate {// Implement Veery Delegate // TODO : Inside the principal class (!!not inside a function) let veery = Veery() override func viewDidLoad() { super.viewDidLoad() // TODO : Init the delegate veery.delegate = self // TODO : declare your API Key Secret veery.setApiKeySecret("SuPeRScrET12345789GhJ") } }
Activate the required functionality level
You should activate the necessary functionality level for every mobile user (see the full documentation to check which level is required for the functionalities you want to use).
Requires ios Veery 1.3.3
1 - Check your Geolocation mode
- FOREGROUND_GEOLOC : geolocalize the user only when the application is in foreground.
- BACKGROUND_GEOLOC : geolocalize the user also when the application is in background.
2 - check veery backend services needed to your App
- COLLECT : Veery will be connected to the backend for historization.
- ROUTE_MATCH : Veery will receive trips computations.
- POINT_OF_INTEREST : Veery will receive Points of interests.
- PREDICTION : Veery will receive Predictions.
Backward compatibility (older than ios Veery 1.3.3)
- FOREGROUND : This is equivalent to Veery.FOREGROUND_GEOLOC.
- BACKGROUND : This is equivalent to Veery.BACKGROUND_GEOLOC.
- BACKEND : This is equivalent to BACKGROUND + Veery.COLLECT + Veery.ROUTE_MATCH.
- GEOPROFILE : This is equivalent to BACKEND + Veery.POINT_OF_INTEREST + Veery.PREDICTION.
You can do that operation whenever you want to activate the user but you should notice that ios will request for required the user rights when called.
class ViewController: UIViewController, VeeryDelegate {// Implement Veery Delegate // TODO : Inside the principal class (!!not inside a function) let veery = Veery() override func viewDidLoad() { super.viewDidLoad() // TODO : Init the delegate veery.delegate = self // TODO : declare your API Key Secret veery.setApiKeySecret("SuPeRScrET12345789GhJ") // TODO : Activate the required function levels (user will be requested to accept geolocation) // veery.activate(service: Veery.GEOPROFILE) // Requires ios Veery 1.3.3 //veery.activate(service:Veery.BACKGROUND_GEOLOC | Veery.COLLECT | Veery.ROUTE_MATCH | Veery.POINT_OF_INTEREST | Veery.PREDICTION) } }
AnyOtherViewController.swift (Optional)
You can declare and use a Veery object in any ViewController where you require geolocation or geoprofilling.
On all those classes you should respect the following template in order to let Veery know:
import Foundation import UIKit import Veery // add this class AnyOtherViewController : UIViewController, VeeryDelegate { let veery = Veery() // add this override func viewDidLoad() { super.viewDidLoad() veery.delegate = self // add this // Required only on the principal ViewController //veery.setApiKeySecret("SuPeRScrET12345789GhJ") // //veery.activate(service: Veery.GEOPROFILE) // Requires ios Veery 1.3.3 //veery.activate(service:Veery.BACKGROUND_GEOLOC | Veery.COLLECT | Veery.ROUTE_MATCH | Veery.POINT_OF_INTEREST | Veery.PREDICTION) } }
Next Steps
Once this compile and runs, you are ready to ask to Veery about the geoprofile and predictions of trips of your users