@@ -29,6 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2929 ]
3030
3131 func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
32+
3233 // Update shortcut items
3334 AppShortcuts . shared. updateShortcutItems ( )
3435
@@ -101,7 +102,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
101102 func applicationWillTerminate( _ application: UIApplication ) {
102103 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
103104 }
104-
105+
106+ // MARK: Helper Functions
107+
108+ /// Creates and sets a unique identifier. If the device identifier changes, updates it.
109+ func setupUniqueIdentifier( ) {
110+ if
111+ let uid = UIDevice . current. identifierForVendor? . uuidString,
112+ uid != userDefaults. string ( forKey: Constants . UserDefaults. uid)
113+ {
114+ userDefaults. set ( uid, forKey: Constants . UserDefaults. uid)
115+ }
116+ }
117+
105118 func handleShortcut( item: UIApplicationShortcutItem ) {
106119 let optionsVC = RouteOptionsViewController ( )
107120 if let shortcutData = item. userInfo as? [ String : Data ] {
@@ -182,9 +195,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
182195 let optionsVC = RouteOptionsViewController ( )
183196
184197 if
185- let lat = items? . filter ( { $0. name == " lat " } ) . first? . value,
186- let long = items? . filter ( { $0. name == " long " } ) . first? . value,
187- let stop = items? . filter ( { $0. name == " stopName " } ) . first? . value {
198+ let lat = items? . filter ( { $0. name == " lat " } ) . first? . value,
199+ let long = items? . filter ( { $0. name == " long " } ) . first? . value,
200+ let stop = items? . filter ( { $0. name == " stopName " } ) . first? . value {
188201 latitude = Double ( lat)
189202 longitude = Double ( long)
190203 stopName = stop
@@ -210,13 +223,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
210223 let longitude = intent. longitude,
211224 let searchTo = intent. searchTo,
212225 let stopName = searchTo. addingPercentEncoding ( withAllowedCharacters: . urlHostAllowed) ,
213- let url = URL ( string: " ithaca-transit://getRoutes?lat= \( latitude) &long= \( longitude) &stopName= \( stopName) " ) {
214- UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
215- return true
226+ let url = URL ( string: " ithaca-transit://getRoutes?lat= \( latitude) &long= \( longitude) &stopName= \( stopName) " )
227+ {
228+ UIApplication . shared. open ( url, options: [ : ] ) { ( didComplete) in
229+ let intentDescription = userActivity. interaction? . intent. intentDescription ?? " No Intent Description "
230+ let payload = SiriShortcutUsedPayload ( didComplete: didComplete,
231+ intentDescription: intentDescription,
232+ locationName: stopName)
233+ Analytics . shared. log ( payload)
216234 }
235+ return true
236+ }
217237 }
218238 return false
219239 }
240+
220241}
221242
222243extension UIWindow {
0 commit comments