diff --git a/.circleci/config.yml b/.circleci/config.yml index b3d554dc5..f08531727 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ 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: @@ -35,11 +35,16 @@ commands: - 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. @@ -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: @@ -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.codecoverage >> -enableCodeCoverage "YES"<> @@ -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" diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9ecef83..eb9afc2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 909f7a3d9..29dbd4aaf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 @@ -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. diff --git a/Cartfile b/Cartfile index 70c46e7cf..bac231d9c 100644 --- a/Cartfile +++ b/Cartfile @@ -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" diff --git a/Cartfile.private b/Cartfile.private index aa130c159..0f2d3cbac 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -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 diff --git a/Cartfile.resolved b/Cartfile.resolved index f804a2dab..3eab55843 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -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" diff --git a/Directions Example/AppDelegate.swift b/Directions Example/AppDelegate.swift index 9c2ab060f..f358f5e3e 100644 --- a/Directions Example/AppDelegate.swift +++ b/Directions Example/AppDelegate.swift @@ -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()) + } } } diff --git a/Directions Example/ContentView.swift b/Directions Example/ContentView.swift new file mode 100644 index 000000000..5c06d3504 --- /dev/null +++ b/Directions Example/ContentView.swift @@ -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.. 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..CFBundlePackageType APPL CFBundleShortVersionString - 1.2.0 + 2.0.0 CFBundleSignature ???? CFBundleVersion - 61 + 68 LSRequiresIPhoneOS NSLocationWhenInUseUsageDescription diff --git a/Directions Example/Launch Screen.storyboard b/Directions Example/Launch Screen.storyboard index 09c0a7b65..026a2622b 100644 --- a/Directions Example/Launch Screen.storyboard +++ b/Directions Example/Launch Screen.storyboard @@ -1,12 +1,8 @@ - - - - - + + + - - - + @@ -22,8 +18,8 @@ -