Skip to content

Commit 8bd162b

Browse files
committed
Update.
1 parent e2437af commit 8bd162b

File tree

3 files changed

+68
-25
lines changed

3 files changed

+68
-25
lines changed

CarPlayExample/AppDelegate.swift

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

CarPlayExample/CustomStyle.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import MapboxNavigation
2+
import MapboxMaps
3+
4+
class CustomStyle: NightStyle {
5+
6+
required init() {
7+
super.init()
8+
9+
mapStyleURL = URL(string: StyleURI.dark.rawValue)!
10+
}
11+
12+
override func apply() {
13+
super.apply()
14+
}
15+
}

Navigation-Examples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
8A3F6B2A26B09C4A009EE612 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8A3F6B2826B09C4A009EE612 /* LaunchScreen.storyboard */; };
2828
8A96379C2492B366008DEF2A /* Route-Deserialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A96379A2492B366008DEF2A /* Route-Deserialization.swift */; };
2929
8A96379D2492B366008DEF2A /* route.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A96379B2492B366008DEF2A /* route.json */; };
30+
8AB316AD26BB0BAF00C3AC76 /* CustomStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB316AC26BB0BAE00C3AC76 /* CustomStyle.swift */; };
3031
8AC9129D2494106100B6941E /* Route-Initialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AC9129C2494106100B6941E /* Route-Initialization.swift */; };
3132
8AE033222628EDFF000E7145 /* Route-Lines-Styling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE033212628EDFF000E7145 /* Route-Lines-Styling.swift */; };
3233
8DF510741FEB08F70049DB9C /* Embedded-Navigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF510731FEB08F70049DB9C /* Embedded-Navigation.swift */; };
@@ -87,6 +88,7 @@
8788
8A3F6B3326B0B253009EE612 /* Entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Entitlements.plist; sourceTree = "<group>"; };
8889
8A96379A2492B366008DEF2A /* Route-Deserialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Route-Deserialization.swift"; sourceTree = "<group>"; };
8990
8A96379B2492B366008DEF2A /* route.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = route.json; sourceTree = "<group>"; };
91+
8AB316AC26BB0BAE00C3AC76 /* CustomStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomStyle.swift; sourceTree = "<group>"; };
9092
8AC9129C2494106100B6941E /* Route-Initialization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Route-Initialization.swift"; sourceTree = "<group>"; };
9193
8AD2F2132489B5C800F81353 /* apply-mapbox-access-token.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "apply-mapbox-access-token.sh"; sourceTree = "<group>"; };
9294
8AE033212628EDFF000E7145 /* Route-Lines-Styling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Route-Lines-Styling.swift"; sourceTree = "<group>"; };
@@ -182,6 +184,7 @@
182184
8A3F6B1C26B09C48009EE612 /* CarPlayExample */ = {
183185
isa = PBXGroup;
184186
children = (
187+
8AB316AC26BB0BAE00C3AC76 /* CustomStyle.swift */,
185188
8A3F6B1D26B09C48009EE612 /* AppDelegate.swift */,
186189
8A3F6B1F26B09C48009EE612 /* SceneDelegate.swift */,
187190
8A3F6B2126B09C48009EE612 /* ViewController.swift */,
@@ -763,6 +766,7 @@
763766
isa = PBXSourcesBuildPhase;
764767
buildActionMask = 2147483647;
765768
files = (
769+
8AB316AD26BB0BAF00C3AC76 /* CustomStyle.swift in Sources */,
766770
8A3F6B2226B09C48009EE612 /* ViewController.swift in Sources */,
767771
8A3F6B1E26B09C48009EE612 /* AppDelegate.swift in Sources */,
768772
8A3F6B2026B09C48009EE612 /* SceneDelegate.swift in Sources */,

0 commit comments

Comments
 (0)