Skip to content

Commit

Permalink
Merge pull request #4690 from mapbox/chizhavko/fix-car-play
Browse files Browse the repository at this point in the history
Fix for carplay
  • Loading branch information
chizhavko committed Jul 23, 2024
2 parents de65a3f + ec6e1e9 commit a48d74e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 68 deletions.
86 changes: 25 additions & 61 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 2.1

orbs:
slack: circleci/[email protected]
macos: circleci/[email protected]
gh: circleci/[email protected]

parameters:
weekly_snapshot:
Expand Down Expand Up @@ -35,19 +37,13 @@ commands:
channel: mobile-bots
event: pass
template: basic_success_1
branch_pattern: main
branch_pattern: lts/v2
- slack/notify:
channel: mobile-bots
event: fail
template: basic_fail_1
branch_pattern: main
branch_pattern: lts/v2
mentions: '@here'
install-gh-cli:
steps:
- run:
name: Install GitHub CLI
command: |
brew install gh
install-xcodegen:
steps:
- run:
Expand Down Expand Up @@ -305,7 +301,7 @@ jobs:
default: false
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
Expand All @@ -316,6 +312,7 @@ jobs:
- *install-gems
- *prepare-mapbox-file
- *prepare-netrc-file
- macos/install-rosetta
- *update-carthage-version
- when:
condition: << parameters.update >>
Expand Down Expand Up @@ -374,13 +371,14 @@ jobs:
default: "MapboxCoreNavigation"
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- checkout
- *prepare-mapbox-file
- *prepare-netrc-file
- macos/install-rosetta
- run:
name: Install prerequisites
command: if [ $(xcversion simulators | grep -cF "iOS << parameters.iOS >> Simulator (installed)") -eq 0 ]; then xcversion simulators --install="iOS << parameters.iOS >>" || true; fi
Expand Down Expand Up @@ -450,7 +448,7 @@ jobs:
default: true
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
Expand All @@ -470,7 +468,7 @@ jobs:
default: "14.1.0"
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
Expand All @@ -492,7 +490,7 @@ jobs:
default: false
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
Expand Down Expand Up @@ -527,13 +525,14 @@ jobs:
default: true
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- checkout
- *prepare-mapbox-file
- *prepare-netrc-file
- macos/install-rosetta
- *add-github-to-known-hosts
- run:
name: Build test host application and execute tests
Expand Down Expand Up @@ -572,7 +571,7 @@ jobs:
xcode: << parameters.xcode >>
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- when:
Expand All @@ -599,6 +598,7 @@ jobs:
- *add-github-to-known-hosts
- *prepare-mapbox-file
- *prepare-netrc-file
- macos/install-rosetta
- *update-carthage-version
- when:
condition: << parameters.is_base_api >>
Expand Down Expand Up @@ -630,14 +630,13 @@ jobs:
xcode: 14.2.0
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- *add-github-to-known-hosts
- *prepare-mapbox-file
- *prepare-netrc-file
- install-mbx-ci
- install-gh-cli
- restore-api-diff-cache:
key: .Environment.CIRCLE_SHA1
is_template: true
Expand All @@ -662,7 +661,7 @@ jobs:
spm-core-integration-test-job:
macos:
xcode: "14.3.1"
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- *prepare-netrc-file
Expand All @@ -674,7 +673,7 @@ jobs:
spm-ui-integration-test-job:
macos:
xcode: "14.1.0"
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- install-bash5
Expand All @@ -695,7 +694,7 @@ jobs:
xcode: << parameters.xcode >>
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- *restore-cache-gems
Expand Down Expand Up @@ -743,7 +742,7 @@ jobs:
xcode: << parameters.xcode >>
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- *restore-cache-gems
Expand Down Expand Up @@ -772,7 +771,7 @@ jobs:
xcode: << parameters.xcode >>
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- *restore-cache-gems
Expand All @@ -795,7 +794,7 @@ jobs:
default: "14.1.0"
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- install-mbx-ci
Expand All @@ -808,7 +807,7 @@ jobs:
default: "14.1.0"
macos:
xcode: << parameters.xcode >>
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.medium.gen1
steps:
- checkout
- install-mbx-ci
Expand Down Expand Up @@ -842,7 +841,7 @@ workflows:
filters:
branches:
only:
- main
- lts/v2
api-diff-workflow:
jobs:
- get-api-log-job:
Expand All @@ -857,15 +856,6 @@ workflows:
requires:
- "Get old API logs"
- "Get new API logs"
# FIXME: Temporarily disabled, failing tests that are executed with MapboxNavigationTestHost should be fixed.
# test-host-workflow:
# jobs:
# - spm-test-host-job:
# name: "swift test; Xcode 13.4.1; iOS 15.5"
# xcode: "13.4.1"
# iOS: "15.5"
# device: "iPhone 13"
# context: Slack Orb
main-workflow:
jobs:
- build-job:
Expand Down Expand Up @@ -959,7 +949,7 @@ workflows:
- ios-trigger-metrics:
filters:
branches:
only: main
only: lts/v2
update-version-workflow:
jobs:
- update-version-job:
Expand All @@ -972,29 +962,3 @@ workflows:
filters:
branches:
only: /^trigger-distribute-version-.*/
# weekly-snapshot-workflow:
# # Run workflow every Friday at 23:59 UTC
# triggers:
# - schedule:
# cron: "59 23 * * 5"
# filters:
# branches:
# only:
# - main
# jobs:
# - release-weekly-snapshot
weekly-snapshot-manual-workflow:
when: << pipeline.parameters.weekly_snapshot >>
jobs:
- release-weekly-snapshot
# pre-snapshot-workflow:
# # Run workflow every Thursday at 23:59 UTC
# triggers:
# - schedule:
# cron: "59 23 * * 4"
# filters:
# branches:
# only:
# - main
# jobs:
# - pre-snapshot-check
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Changes to the Mapbox Navigation SDK for iOS

## v2.18.2

### CarPlay

* Fixed CarPlay crash when calling `CarPlayManager.routePreview()` function for iOS 14+.

## v2.18.1

### CarPlay

* Fixed CarPlay crash when calling `CarPlayManager.routePreview()` function.
* Partially fixed CarPlay crash when calling `CarPlayManager.routePreview()` function.

## v2.18.0

Expand Down
16 changes: 15 additions & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ class ViewController: UIViewController {
guard let delegate = UIApplication.shared.delegate as? AppDelegate else { return }
if let indexedRouteResponse = indexedRouteResponse {
delegate.carPlayManager.previewRoutes(for: indexedRouteResponse)

// debug
// By enabling following lines, it makes easy to reproduce the same crash.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
delegate.carPlayManager.previewRoutes(for: indexedRouteResponse)
}
} else {
delegate.carPlayManager.cancelRoutesPreview()
}
Expand All @@ -251,7 +257,15 @@ class ViewController: UIViewController {
}

@IBAction func simulateButtonPressed(_ sender: Any) {
simulationButton.isSelected = !simulationButton.isSelected
// simulationButton.isSelected = !simulationButton.isSelected

let destinationCoordinate = CLLocationCoordinate2D(latitude: 37.957453, longitude: -122.523200)
let waypoint = Waypoint(coordinate: destinationCoordinate, name: "Dropped Pin #\(waypoints.endIndex + 1)")

waypoint.targetCoordinate = destinationCoordinate
waypoints = [waypoint]

requestRoute()
}

@IBAction func clearMapPressed(_ sender: Any) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxNavigation/CPInterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public extension CPInterfaceController {
animated or not.
*/
func safePopTemplate(animated: Bool) {
if templates.count == 1 { return }
guard templates.count > 1 else { return }

popTemplate(animated: animated)
}
}
13 changes: 10 additions & 3 deletions Sources/MapboxNavigation/CarPlayManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class CarPlayManager: NSObject {
private weak var navigationService: NavigationService?
private var idleTimerCancellable: IdleTimerManager.Cancellable?
private var indexedRouteResponse: IndexedRouteResponse?

/**
Programatically begins a CarPlay turn-by-turn navigation session.
Expand Down Expand Up @@ -653,6 +653,7 @@ extension CarPlayManager {
}

func previewRoutes(for trip: CPTrip) {

guard let traitCollection = (self.carWindow?.rootViewController as? CarPlayMapViewController)?.traitCollection,
let interfaceController = interfaceController else {
return
Expand All @@ -673,8 +674,14 @@ extension CarPlayManager {
previewMapTemplate.showTripPreviews([modifiedTrip], textConfiguration: previewText)

if currentActivity == .previewing {
interfaceController.safePopTemplate(animated: false)
interfaceController.pushTemplate(previewMapTemplate, animated: false)
if #available(iOS 14.0, *) {
interfaceController.popTemplate(animated: false) { _, _ in
interfaceController.pushTemplate(previewMapTemplate, animated: false)
}
} else {
interfaceController.safePopTemplate(animated: false)
interfaceController.pushTemplate(previewMapTemplate, animated: false)
}
} else {
interfaceController.pushTemplate(previewMapTemplate, animated: true)
}
Expand Down

0 comments on commit a48d74e

Please sign in to comment.