Booking Rides using SiriKit
In iOS 10, SiriKit can be used to add app’s services with a system. SiriKit provides services for the below-mentioned domains. To avail it, you need to create an app extension using the Intents and Intents UI framework:
- Audio or video calling
- Messaging
- Sending or receiving payments
- Searching photos
- Making restaurant reservations
- Ride Booking
- Workouts
- Adjusting settings in a CarPlay-enabled vehicle
Intents: You need to perform associated tasks respective to Intents and this extension is required for this. Basically, intents are tasks related to a domain, which is performed by an app. Each intent is represented by custom class where you can modify information for a specified task.
Intents UI: It is an optional extension to customize Siri or map after intent has been handled.
Steps to create Intent extension:
- Create a new iOS Project
- Switch on Siri capability from capabilities tab in iOS app target
- Select File->New->Target, from here add “Intent Extension” from application extensions, you can add one or more extensions.
- New folder of extension and extensionUI will be created in your project. Here extensionUI is optional to choose, use it only if you want to customise map after intent has been handled.
- In info.plist of Intent Extension, select NSExtension->NSExtensionAttributes->IntentsSupported
- Add items in IntentsSupported, default you will get INSendMessageIntent, INSearchForMessagesIntent, INSetMessageAttributeIntent. But for booking a ride you need to change it to INRequestRideIntent, INGetRideStatusIntent, INListRideOptionsIntent. You can add multiple intent and the sequence of intent will decide priority for same.
- In info.plist of app add key NSSiriUsageDescription/Privacy – Siri Usage Description, here you have to add product description.
- in didFinishLaunching of app delegate, make request for Siri: INPreferences.requestSiriAuthorization{status in print(status)}
- In IntentHandler.swift class, add appropriate intents and make sure to declare same in info.plist
- Customize INListRideOptionsIntentHandling delegate in IntentHandler.swift class as per your requirement to show Ride price, time left and any other message.
- Build App with selection of extension scheme, option will open to select Siri
- Run App on device
- Now you can test example by saying things to Siri
- Make sure to upload GeoJSON file as your app’s Routing App Coverage File in iTunes Connect with the regions specified for which you are going to provide ride service.