Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose offline routing functionality to Obj-C #1891

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions MapboxCoreNavigation/OfflineDirections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -89,6 +89,7 @@ public class NavigationDirections: Directions {
- parameter progressHandler: Unpacking reports progress every 500ms.
- parameter completionHandler: Called when unpacking completed.
*/
@objc(unpackTilePackAtURL:outputDirectoryURL:progressHandler:completionHandler:)
public class func unpackTilePack(at filePathURL: URL, outputDirectoryURL: URL, progressHandler: UnpackProgressHandler?, completionHandler: UnpackCompletionHandler?) {

NavigationDirectionsConstants.offlineSerialQueue.sync {
Expand Down Expand Up @@ -134,6 +135,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 {
Expand Down
38 changes: 38 additions & 0 deletions MapboxCoreNavigationTests/BridgingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import MapboxCoreNavigation;
@import MapboxDirections;
@import TestHelper;
@import MapKit;

@interface BridgingTests : XCTestCase
@property (nonatomic) MBRouteController *routeController;
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we excluding it because the networking is currently unstubbed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, kind of. These tests are just to make sure we don't regress Obj-C bridging.
We have offline tests for fetching available versions, downloading tiles, and unpacking tiles written in Swift with stubbed network.

- (void)testOfflineRouting {
[[[MBDirections sharedDirections] fetchAvailableOfflineVersionsWithCompletionHandler:^(NSArray<NSString *> * _Nullable versions, NSError * _Nullable error) {

NSArray <NSValue *> *coordinates = nil;
coordinates = @[[NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(0, 0)],
[NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(1, 1)]];

MBCoordinateBounds *bounds = [[MBCoordinateBounds alloc] init:coordinates];
Copy link
Contributor Author

@frederoni frederoni Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init should be refined for Obj-C

PR in mapbox/mapbox-directions-swift#325


[[[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 unpackTilePackAtURL: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<MBWaypoint *> * _Nullable waypoints, NSArray<MBRoute *> * _Nullable routes, NSError * _Nullable error) {

}];

NSURL *url = [NSURL URLWithString:@""];
[directions configureRouterWithTilesURL:url translationsURL:url completionHandler:^(uint64_t numberOfTiles) {

}];
}

@end

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
ReferencedContainer = "container:MapboxNavigation.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "BridgingTests/testOfflineRouting">
</Test>
<Test
Identifier = "MapboxNavigationTests/testLowAlert()">
</Test>
Expand Down