@@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIWindowSceneDelegate {
1111 var window : UIWindow ?
1212
1313 @available ( iOS 12 . 0 , * )
14- lazy var carPlayManager : CarPlayManager = CarPlayManager ( )
14+ lazy var carPlayManager : CarPlayManager = CarPlayManager ( styles : [ CustomStyle ( ) ] )
1515}
1616
1717// MARK: - UIApplicationDelegate methods
@@ -55,8 +55,6 @@ extension AppDelegate: CPTemplateApplicationSceneDelegate {
5555 appDelegate. carPlayManager. templateApplicationScene ( templateApplicationScene,
5656 didConnectCarInterfaceController: interfaceController,
5757 to: window)
58-
59- appDelegate. carPlayManager. interfaceController? . delegate = self
6058 }
6159
6260 func templateApplicationScene( _ templateApplicationScene: CPTemplateApplicationScene ,
@@ -82,13 +80,24 @@ extension AppDelegate: CarPlayManagerDelegate {
8280
8381 func carPlayManager( _ carPlayManager: CarPlayManager ,
8482 leadingNavigationBarButtonsCompatibleWith traitCollection: UITraitCollection ,
85- in carPlayTemplate: CPTemplate , for activity: CarPlayActivity ) -> [ CPBarButton ] ? {
86- let barButton = CPBarButton ( type: . text) { _ in
83+ in carPlayTemplate: CPTemplate ,
84+ for activity: CarPlayActivity ) -> [ CPBarButton ] ? {
85+ switch activity {
86+
87+ case . browsing:
88+ break
8789
90+ case . panningInBrowsingMode:
91+ break
92+
93+ case . previewing:
94+ break
95+
96+ case . navigating:
97+ break
8898 }
89- barButton. title = " Test "
9099
91- return [ barButton ]
100+ return [ ]
92101 }
93102
94103 func carPlayManager( _ carPlayManager: CarPlayManager ,
@@ -107,22 +116,16 @@ extension AppDelegate: CarPlayManagerDelegate {
107116 break
108117
109118 case . navigating:
110- break
111-
119+ return [ carPlayManager. exitButton]
112120 }
113121
114- let barButton = CPBarButton ( type: . text) { _ in
115-
116- }
117- barButton. title = " Test "
118-
119- return [ barButton]
122+ return [ ]
120123 }
121124
122125 func carPlayManager( _ carPlayManager: CarPlayManager ,
123126 mapButtonsCompatibleWith traitCollection: UITraitCollection ,
124127 in carPlayTemplate: CPTemplate ,
125- for activity: CarPlayActivity ) -> [ CPMapButton ] {
128+ for activity: CarPlayActivity ) -> [ CPMapButton ] ? {
126129 switch activity {
127130
128131 case . browsing:
@@ -136,15 +139,9 @@ extension AppDelegate: CarPlayManagerDelegate {
136139
137140 case . navigating:
138141 break
139-
140142 }
141143
142- let mapButton = CPMapButton { _ in
143-
144- }
145- mapButton. image = UIImage . checkmark
146-
147- return [ mapButton]
144+ return [ ]
148145 }
149146
150147 func carPlayManager( _ carPlayManager: CarPlayManager ,
@@ -185,24 +182,51 @@ extension AppDelegate: CarPlayManagerDelegate {
185182
186183 }
187184
185+ // Delegate method, which is called after ending active-guidance navigation session and dismissing
186+ // `CarPlayNavigationViewController`.
188187 func carPlayManagerDidEndNavigation( _ carPlayManager: CarPlayManager ) {
188+ let alertAction = CPAlertAction ( title: " OK " ,
189+ style: . default,
190+ handler: { [ weak self] _ in
191+ self ? . carPlayManager. interfaceController? . dismissTemplate ( animated: true )
192+ } )
193+
194+ let alertTemplate = CPAlertTemplate ( titleVariants: [ " Did end active-guidance navigation. " ] ,
195+ actions: [ alertAction] )
189196
197+ carPlayManager. interfaceController? . presentTemplate ( alertTemplate, animated: true )
190198 }
191199
200+ // Delegate method, which allows to show `CPActionSheetTemplate` or `CPAlertTemplate`
201+ // after arriving to the specific `Waypoint`.
192202 func carPlayManager( _ carPlayManager: CarPlayManager ,
193203 shouldPresentArrivalUIFor waypoint: Waypoint ) -> Bool {
194- return false
204+ return true
195205 }
196206
207+ // Delegate method, which provides the ability to disable the idle timer to avert system sleep.
197208 func carPlayManagerShouldDisableIdleTimer( _ carPlayManager: CarPlayManager ) -> Bool {
198- return false
209+ return true
199210 }
200211
212+ // Delegate method, which is called right after starting active-guidance navigation and presenting
213+ // `CarPlayNavigationViewController`.
201214 func carPlayManager( _ carPlayManager: CarPlayManager ,
202215 didPresent navigationViewController: CarPlayNavigationViewController ) {
216+ let alertAction = CPAlertAction ( title: " OK " ,
217+ style: . default,
218+ handler: { [ weak self] _ in
219+ self ? . carPlayManager. interfaceController? . dismissTemplate ( animated: true )
220+ } )
221+
222+ let alertTemplate = CPAlertTemplate ( titleVariants: [ " Did present CarPlayNavigationViewController. " ] ,
223+ actions: [ alertAction] )
203224
225+ carPlayManager. interfaceController? . presentTemplate ( alertTemplate, animated: true )
204226 }
205227
228+ // Delegate method, which allows to modify final destination annotation whenever its added to
229+ // `CarPlayMapViewController` or `CarPlayNavigationViewController`.
206230 func carPlayManager( _ carPlayManager: CarPlayManager ,
207231 didAdd finalDestinationAnnotation: PointAnnotation ,
208232 to parentViewController: UIViewController ,
0 commit comments