Skip to content

Commit

Permalink
Merge pull request #558 from mapbox/release-v2.0
Browse files Browse the repository at this point in the history
Merge release-v2.0 to main (as of v2.0.0-beta.5)
  • Loading branch information
1ec5 authored Jul 1, 2021
2 parents 5ad4613 + 2a8245b commit 773a627
Show file tree
Hide file tree
Showing 69 changed files with 785 additions and 1,178 deletions.
76 changes: 57 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ commands:
- run:
name: Install Carthage
command: |
curl -OL "https://github.com/Carthage/Carthage/releases/download/0.34.0/Carthage.pkg"
curl -OL "https://github.com/Carthage/Carthage/releases/download/0.38.0/Carthage.pkg"
sudo installer -pkg Carthage.pkg -target /
publish-codecov:
steps:
- run:
name: Publish Code Coverage
command: bash <(curl -s https://codecov.io/bash)
carthage-bootstrap:
steps:
- run:
name: Dependencies
command: carthage bootstrap --platform all --cache-builds --configuration Debug --use-xcframeworks

jobs:
spm-linux-job:
docker:
- image: swift:5.3
- image: swift:5.4
steps:
- checkout
# Limiting number of parallel jobs to avoid build crash bug.
Expand All @@ -57,6 +62,41 @@ jobs:
steps:
- checkout
- run: swift build

carthage-integration-test:
parameters:
xcode:
type: string
macos:
xcode: << parameters.xcode >>
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- install-mapbox-token
- install-carthage
- run:
name: "Create integration Cartfile"
command: |
echo 'github "mapbox/mapbox-directions-swift"' \"$CIRCLE_SHA1\" > Cartfile
- run:
name: "Build"
command: |
carthage bootstrap --platform all --use-netrc --use-xcframeworks
example-app-build:
macos:
xcode: "12.4.0"
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- checkout
- install-mapbox-token
- install-carthage
- restore-cache
- carthage-bootstrap
- run:
name: "Build example app"
command: xcodebuild -sdk iphonesimulator -project MapboxDirections.xcodeproj -scheme 'Example' -destination 'platform=iOS Simulator,OS=14.4,name=iPhone 12 Pro Max' clean build
- save-cache

build-job:
parameters:
Expand Down Expand Up @@ -93,13 +133,7 @@ jobs:
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
- run:
name: Dependencies
command: |
./scripts/wcarthage.sh bootstrap --platform ios --cache-builds --configuration Debug --no-use-binaries
./scripts/wcarthage.sh bootstrap --platform tvos --cache-builds --configuration Debug --no-use-binaries
./scripts/wcarthage.sh bootstrap --platform macos --cache-builds --configuration Debug --no-use-binaries
./scripts/wcarthage.sh bootstrap --platform watchos --cache-builds --configuration Debug --no-use-binaries
- carthage-bootstrap
- run:
name: iOS
command: xcodebuild -sdk iphonesimulator -project MapboxDirections.xcodeproj -scheme 'MapboxDirections iOS' -destination 'platform=iOS Simulator,OS=<< parameters.iOS >>,name=<< parameters.device >>' clean build <<# parameters.test >>test<</ parameters.test >><<# parameters.codecoverage >> -enableCodeCoverage "YES"<</ parameters.codecoverage >>
Expand All @@ -126,20 +160,24 @@ workflows:
workflow:
jobs:
- build-job:
name: "Xcode_12.1"
name: "Dev Build: Xcode 12.0"
xcode: "12.0.0"
iOS: "14.0"
tvOS: "14.0"
watchOS: "7.0"
- build-job:
name: "Xcode_11.1"
xcode: "11.1.0"
iOS: "13.1"
tvOS: "13.0"
watchOS: "6.0"
codecoverage: false
- carthage-integration-test:
name: "Carthage Integration Test 12.0"
xcode: "12.0.0"
- carthage-integration-test:
name: "Carthage Integration Test 12.4"
xcode: "12.4.0"
- spm-job:
name: "SPM_build"
name: "SPM build 12.0.0"
xcode: "12.0.0"
- spm-job:
name: "SPM build 12.4.0"
xcode: "12.4.0"
- spm-linux-job:
name: "SPM_Ubuntu_build"
name: "SPM Ubuntu build"
- example-app-build:
name: "Build example app"
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changes to Mapbox Directions for Swift

## v2.0.0

* To gain access to the Mapbox Directions and Map Matching APIs, set `MBXAccessToken` in your Info.plist. `MGLMapboxAccessToken` is still supported but is now deprecated. ([#522](https://github.com/mapbox/mapbox-directions-swift/pull/522))
* This library requires Turf v2.0.0-alpha.3. ([#525](https://github.com/mapbox/mapbox-directions-swift/pull/525))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))
* Added the `Intersection.preferredApproachLanes` and `Intersection.usableLaneIndication` properties that indicate preferred lane usage. `VisualInstruction.Component.lane(indications:isUsable:)` has been renamed to `VisualInstruction.Component.lane(indications:isUsable:preferredDirection:)`. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
* Comparing two `Intersection`s with `==` now considers whether the `Intersection.restStop`, `Intersection.regionCode`, and `Intersection.outletMapboxStreetsRoadClass` properties are equal. ([#529](https://github.com/mapbox/mapbox-directions-swift/pull/529))
* Carthage v0.38 or above is now required for installing this SDK if you use Carthage. ([#548](https://github.com/mapbox/mapbox-directions-swift/pull/548))
* Xcode 12.0 or above is now required to build MapboxDirections from source. ([#548](https://github.com/mapbox/mapbox-directions-swift/pull/548))
* You can fully build this SDK on Macs with Apple Silicon. ([#548](https://github.com/mapbox/mapbox-directions-swift/pull/548))

## v1.2.0

### Packaging
Expand Down
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ To contribute code changes to this project, use either Carthage or Swift Package

### Using Carthage

1. Install Xcode 12 and [Carthage](https://github.com/Carthage/Carthage/) v0.35 or above.
1. Run `./scripts/wcarthage.sh bootstrap --cache-builds`. (wcarthage.sh is a temporary workaround for [a linker error in Xcode 12](https://github.com/Carthage/Carthage/issues/3019).)
1. Once the Carthage build finishes, open MapboxDirections.xcodeproj in Xcode and build the MapboxDirections Mac scheme. Switch to the Example scheme to see the Mapbox Directions API in action on iOS.
1. Install Xcode 12 and [Carthage](https://github.com/Carthage/Carthage/) v0.38 or above.
1. Run `carthage bootstrap --platform all --use-xcframeworks`.
1. Once the Carthage build finishes, open MapboxDirections.xcodeproj in Xcode and build the MapboxDirections Mac scheme.

### Using Swift Package Manager

Expand Down Expand Up @@ -54,12 +54,10 @@ To add any type, constant, or member to the package’s public interface:

1. Add a file to Tests/MapboxDirectionsTests/
1. Add a file reference to the MapboxDirectionsTests group in MapboxDirections.xcodeproj.
1. Rerun `swift test --generate-linuxmain`, which updates [XCTestManifests.swift](./Tests/MapboxDirectionsTests/XCTestManifests.swift) for builds that use Swift Package Manager.

### Adding a test case

1. Add a `test*` method to one of the classes in one of the files in [Tests/MapboxDirectionsTests/](./Tests/MapboxDirectionsTests/).
1. Rerun `swift test --generate-linuxmain`, which updates [XCTestManifests.swift](./Tests/MapboxDirectionsTests/XCTestManifests.swift) for builds that use Swift Package Manager.

### Adding a test fixture

Expand All @@ -83,7 +81,7 @@ To release a new version of the MapboxDirections package:
1. Run `./scripts/update-version.sh v#.#.#`, where _#.#.#_ is a new version number conforming to [Semantic Versioning](https://semver.org/). Commit the changes with a commit message like `v#.#.#` and open a pull request to get it reviewed and merged.
1. Tag the merged changes as `v#.#.#`. Push the tag by running `git pull && git push origin v#.#.#`.
1. [Create a new release](https://github.com/mapbox/mapbox-directions-swift/releases/new/). Add release notes based on the release’s section in the changelog. (Unlike the changelog, release notes accept `#123` syntax for linking to PRs.) Title the release `v#.#.#`. Check “This is a pre-release” if applicable, then click “Publish release”.
1. Run `pod repo update && pod trunk push` to publish the release on CocoaPods trunk.
1. Run `pod repo update && pod trunk push MapboxDirections.podspec` (or `pod trunk push MapboxDirections-pre.podspec` for a prerelease) to publish the release on CocoaPods trunk.
1. Run `./scripts/publish-documentation.sh v#.#.#` to generate and publish the documentation. Create a pull request and set the base branch to `publisher-production`.
1. Wait for new documentation to be live. Once you merge the branch into `publisher-production`, the new version will be available within 10 minutes. (Mapbox employees can check the #publisher channel in Slack for a notification of when the commit has been published.)
1. _(Mapbox employees only.)_ [Update various links](https://github.com/mapbox/ios-sdk#mapboxdirectionsswift) to the current docset in the [iOS documentation] site.
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "raphaelmor/Polyline" ~> 5.0
github "mapbox/turf-swift" ~> 1.0
github "mapbox/turf-swift" "v2.0.0-beta.1"
github "Udumft/SwiftCLI" "carthage-fix"
1 change: 0 additions & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 5.5
github "AliSoftware/OHHTTPStubs" ~> 9.0
github "mapbox/mapbox-events-ios" ~> 0.10
5 changes: 2 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "5.9.0"
github "AliSoftware/OHHTTPStubs" "9.1.0"
github "Udumft/SwiftCLI" "da19d2a16cd5aa838d8fb7256e28c171bc67dd82"
github "mapbox/mapbox-events-ios" "v0.10.7"
github "mapbox/turf-swift" "v1.2.0"
github "mapbox/mapbox-events-ios" "v0.10.8"
github "mapbox/turf-swift" "v2.0.0-beta.1"
github "raphaelmor/Polyline" "v5.0.2"
18 changes: 7 additions & 11 deletions Directions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import UIKit
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = ViewController(nibName: nil, bundle: nil)
window!.makeKeyAndVisible()

return true
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView(vm: DirectionsViewModel())
}
}
}
135 changes: 135 additions & 0 deletions Directions Example/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import Foundation
import SwiftUI
import Combine
import MapboxDirections

final class DirectionsViewModel: ObservableObject {
private let distanceFormatter: LengthFormatter = .init()
private let travelTimeFormatter: DateComponentsFormatter = .init()

@Published
var routes: [Route] = []

init() {
travelTimeFormatter.unitsStyle = .short
}

func loadRoutes() {
let startPoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047),
name: "Mapbox")
let stopPoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.89065720, longitude: -77.0090701),
name: "Capitol")
let endPoint = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365),
name: "White House")
let options = RouteOptions(waypoints: [startPoint, stopPoint, endPoint])
options.includesSteps = true
options.routeShapeResolution = .full
options.attributeOptions = [.congestionLevel, .maximumSpeedLimit]

Directions.shared.calculate(options) { (session, result) in
switch result {
case let .failure(error):
print("Error calculating directions: \(error)")
case let .success(response):
self.routes = response.routes ?? []
}
}
}

func formattedDistance(for route: Route) -> String {
return distanceFormatter.string(fromMeters: route.distance)
}

func formattedTravelTime(for route: Route) -> String {
return travelTimeFormatter.string(from: route.expectedTravelTime)!
}

func formattedTypicalTravelTime(for route: Route) -> String {
if let typicalTravelTime = route.typicalTravelTime,
let formattedTypicalTravelTime = travelTimeFormatter.string(from: typicalTravelTime) {
return formattedTypicalTravelTime
}
else {
return "Not available"
}
}

func stepDescriptions(for step: RouteStep) -> String {
var description: String = ""
let direction = step.maneuverDirection?.rawValue ?? "none"
description.append("\(step.instructions) [\(step.maneuverType) \(direction)]")
if step.distance > 0 {
let formattedDistance = distanceFormatter.string(fromMeters: step.distance)
description.append(" (\(step.transportType) for \(formattedDistance))")
}
return description
}
}

struct ContentView: View {
@ObservedObject
var vm: DirectionsViewModel

var body: some View {
ScrollView {
LazyVStack(spacing: 10, content: {
ForEach(vm.routes, id: \.routeIdentifier) { route in
VStack(alignment: .leading, spacing: 3) {
headerView(for: route)
ForEach(0..<route.legs.count, id: \.self) { legIdx in
if let source = route.legs[legIdx].source?.name,
let destination = route.legs[legIdx].destination?.name {
Text("From '\(source)' to '\(destination)'").font(.title2)
}
else {
Text("Steps:").font(.title2)
}
stepsView(for: route.legs[legIdx])
}
}
}
})
}
.padding(5)
.onAppear { vm.loadRoutes() }
}

@ViewBuilder
private func headerView(for route: Route) -> some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Route: ").fontWeight(.bold)
Text(route.description)
.fixedSize(horizontal: false, vertical: true)
}
HStack {
Text("Distance: ").fontWeight(.bold)
Text(vm.formattedDistance(for:route))
}
HStack {
Text("ETA: ").fontWeight(.bold)
Text(vm.formattedTravelTime(for: route))
}
HStack {
Text("Typical travel time: ").fontWeight(.bold)
Text(vm.formattedTypicalTravelTime(for: route))
}
Divider()
}
}

@ViewBuilder
private func stepsView(for leg: RouteLeg) -> some View {
LazyVStack(alignment: .leading, spacing: 5, content: {
ForEach(0..<leg.steps.count, id: \.self) { stepIdx in
HStack {
Text("\(stepIdx + 1). ").fontWeight(.bold)
Text(vm.stepDescriptions(for: leg.steps[stepIdx]))
}
.padding([.top, .bottom], 3)

Divider()
}
})
}
}
4 changes: 2 additions & 2 deletions Directions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.0</string>
<string>2.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>61</string>
<string>68</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
Expand Down
16 changes: 6 additions & 10 deletions Directions Example/Launch Screen.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -22,8 +18,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="View route steps in the console." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="20" y="626.5" width="335" height="21"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="View route steps." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="20" y="626" width="335" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand Down
Loading

0 comments on commit 773a627

Please sign in to comment.