From 18dcd61e2dcbe7dac53eaaa821d64f077c6f9266 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Thu, 6 Dec 2018 19:46:10 +0200 Subject: [PATCH 1/3] Expose offline routing functionality to Obj-C --- MapboxCoreNavigation/OfflineDirections.swift | 7 ++-- MapboxCoreNavigationTests/BridgingTests.m | 38 +++++++++++++++++++ .../xcschemes/MapboxCoreNavigation.xcscheme | 3 ++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/MapboxCoreNavigation/OfflineDirections.swift b/MapboxCoreNavigation/OfflineDirections.swift index 42f0337abe..a0488ed61c 100644 --- a/MapboxCoreNavigation/OfflineDirections.swift +++ b/MapboxCoreNavigation/OfflineDirections.swift @@ -56,7 +56,7 @@ public typealias UnpackCompletionHandler = (_ numberOfTiles: UInt64, _ error: Er @objc(MBNavigationDirections) public class NavigationDirections: Directions { - public override init(accessToken: String? = nil, host: String? = nil) { + @objc public override init(accessToken: String? = nil, host: String? = nil) { super.init(accessToken: accessToken, host: host) } @@ -67,7 +67,7 @@ public class NavigationDirections: Directions { - parameter translationsURL: The location where the translations has been downloaded to. - parameter completionHandler: A block that is called when the router is completely configured. */ - public func configureRouter(tilesURL: URL, translationsURL: URL? = nil, completionHandler: @escaping NavigationDirectionsCompletionHandler) { + @objc public func configureRouter(tilesURL: URL, translationsURL: URL? = nil, completionHandler: @escaping NavigationDirectionsCompletionHandler) { NavigationDirectionsConstants.offlineSerialQueue.sync { // Translations files bundled within navigation native @@ -89,7 +89,7 @@ public class NavigationDirections: Directions { - parameter progressHandler: Unpacking reports progress every 500ms. - parameter completionHandler: Called when unpacking completed. */ - public class func unpackTilePack(at filePathURL: URL, outputDirectoryURL: URL, progressHandler: UnpackProgressHandler?, completionHandler: UnpackCompletionHandler?) { + @objc public class func unpackTilePack(at filePathURL: URL, outputDirectoryURL: URL, progressHandler: UnpackProgressHandler?, completionHandler: UnpackCompletionHandler?) { NavigationDirectionsConstants.offlineSerialQueue.sync { @@ -134,6 +134,7 @@ public class NavigationDirections: Directions { - parameter offline: Determines whether to calculate the route offline or online. - parameter completionHandler: The closure (block) to call with the resulting routes. This closure is executed on the application’s main thread. */ + @objc(calculateDirectionsWithOptions:offline:completionHandler:) public func calculate(_ options: RouteOptions, offline: Bool = true, completionHandler: @escaping Directions.RouteCompletionHandler) { guard offline == true else { diff --git a/MapboxCoreNavigationTests/BridgingTests.m b/MapboxCoreNavigationTests/BridgingTests.m index 0c7b5b718f..57253ed96e 100644 --- a/MapboxCoreNavigationTests/BridgingTests.m +++ b/MapboxCoreNavigationTests/BridgingTests.m @@ -4,6 +4,7 @@ @import MapboxCoreNavigation; @import MapboxDirections; @import TestHelper; +@import MapKit; @interface BridgingTests : XCTestCase @property (nonatomic) MBRouteController *routeController; @@ -41,6 +42,43 @@ - (void)testUpdateRoute { _routeController.routeProgress = [[MBRouteProgress alloc] initWithRoute:route legIndex:0 spokenInstructionIndex:0]; [self waitForExpectations:@[expectation] timeout:5]; } + +// This test is excluded from the test suite. We are just verifying that offline routing bridges to Obj-C at compile time. +- (void)testOfflineRouting { + [[[MBDirections sharedDirections] fetchAvailableOfflineVersionsWithCompletionHandler:^(NSArray * _Nullable versions, NSError * _Nullable error) { + + NSArray *coordinates = nil; + coordinates = @[[NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(0, 0)], + [NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(1, 1)]]; + + MBCoordinateBounds *bounds = [[MBCoordinateBounds alloc] init:coordinates]; + + [[[MBDirections sharedDirections] downloadTilesIn:bounds version:versions.firstObject session:nil completionHandler:^(NSURL * _Nullable url, NSURLResponse * _Nullable response, NSError * _Nullable error) { + + NSURL *outputDirectoryURL = [[NSBundle mapboxCoreNavigation] suggestedTileURLWithVersion:versions.firstObject]; + + [MBNavigationDirections unpackTilePackAt:url outputDirectoryURL:outputDirectoryURL progressHandler:^(uint64_t totalBytes, uint64_t bytesRemaining) { + // Show unpacking progress + } completionHandler:^(uint64_t numberOfTiles, NSError * _Nullable error) { + // Dismiss UI + }]; + + }] resume]; + }] resume]; + + MBNavigationRouteOptions *options = [[MBNavigationRouteOptions alloc] initWithLocations:@[] profileIdentifier:MBDirectionsProfileIdentifierCycling]; + + MBNavigationDirections *directions = nil; + + [directions calculateDirectionsWithOptions:options offline:YES completionHandler:^(NSArray * _Nullable waypoints, NSArray * _Nullable routes, NSError * _Nullable error) { + + }]; + + NSURL *url = [NSURL URLWithString:@""]; + [directions configureRouterWithTilesURL:url translationsURL:url completionHandler:^(uint64_t numberOfTiles) { + + }]; +} @end diff --git a/MapboxNavigation.xcodeproj/xcshareddata/xcschemes/MapboxCoreNavigation.xcscheme b/MapboxNavigation.xcodeproj/xcshareddata/xcschemes/MapboxCoreNavigation.xcscheme index ad3fa7f859..a6e1bc21d5 100644 --- a/MapboxNavigation.xcodeproj/xcshareddata/xcschemes/MapboxCoreNavigation.xcscheme +++ b/MapboxNavigation.xcodeproj/xcshareddata/xcschemes/MapboxCoreNavigation.xcscheme @@ -48,6 +48,9 @@ ReferencedContainer = "container:MapboxNavigation.xcodeproj"> + + From becd04fece67d17918eb2e7f083f70c78621074d Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 10 Dec 2018 14:45:00 +0100 Subject: [PATCH 2/3] Refine unpack obj-c signature --- MapboxCoreNavigation/OfflineDirections.swift | 3 ++- MapboxCoreNavigationTests/BridgingTests.m | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MapboxCoreNavigation/OfflineDirections.swift b/MapboxCoreNavigation/OfflineDirections.swift index a0488ed61c..f0e338bc5b 100644 --- a/MapboxCoreNavigation/OfflineDirections.swift +++ b/MapboxCoreNavigation/OfflineDirections.swift @@ -89,7 +89,8 @@ public class NavigationDirections: Directions { - parameter progressHandler: Unpacking reports progress every 500ms. - parameter completionHandler: Called when unpacking completed. */ - @objc public class func unpackTilePack(at filePathURL: URL, outputDirectoryURL: URL, progressHandler: UnpackProgressHandler?, completionHandler: UnpackCompletionHandler?) { + @objc(unpackTilePackAtURL:outputDirectoryURL:progressHandler:completionHandler:) + public class func unpackTilePack(at filePathURL: URL, outputDirectoryURL: URL, progressHandler: UnpackProgressHandler?, completionHandler: UnpackCompletionHandler?) { NavigationDirectionsConstants.offlineSerialQueue.sync { diff --git a/MapboxCoreNavigationTests/BridgingTests.m b/MapboxCoreNavigationTests/BridgingTests.m index 57253ed96e..9911e8d8b7 100644 --- a/MapboxCoreNavigationTests/BridgingTests.m +++ b/MapboxCoreNavigationTests/BridgingTests.m @@ -57,7 +57,7 @@ - (void)testOfflineRouting { NSURL *outputDirectoryURL = [[NSBundle mapboxCoreNavigation] suggestedTileURLWithVersion:versions.firstObject]; - [MBNavigationDirections unpackTilePackAt:url outputDirectoryURL:outputDirectoryURL progressHandler:^(uint64_t totalBytes, uint64_t bytesRemaining) { + [MBNavigationDirections unpackTilePackAtURL:url outputDirectoryURL:outputDirectoryURL progressHandler:^(uint64_t totalBytes, uint64_t bytesRemaining) { // Show unpacking progress } completionHandler:^(uint64_t numberOfTiles, NSError * _Nullable error) { // Dismiss UI From 667ec1ea03f64b7c6f3167633c49b2ad0a299fba Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 17 Dec 2018 13:02:21 +0100 Subject: [PATCH 3/3] Add a blurb in the changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c79ddbd4f..d8d7992057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes to the Mapbox Navigation SDK for iOS +## master + +* The `NavigationDirections.unpackTilePack(at:outputDirectoryURL:progressHandler:completionHandler:)` method is now available to Objective-C code as `-[MBNavigationDirections unpackTilePackAtURL:outputDirectoryURL:progressHandler:completionHandler:]`. ([#1891](https://github.com/mapbox/mapbox-navigation-ios/pull/1891)) + ## v0.26.0 ### Client-side routing