I am currently developing an app in React Native and have chosen to use the Mapbox iOS SDK. All components have been added successfully, only now I get stuck in the last step. I've followed a blog post but I assume it's outdated (https://medium.com/@113408/turn-by-turn-navigation-using-react-native-and-mapbox-eb42c79a0a77) now at the bridge code I have copied that 1-on-1 and this is as follows:
import Foundation
import UIKit
import MapboxCoreNavigation
import MapboxNavigation
import MapboxDirections
import Mapbox
@objc(NavDemo)
class NavDemo: NSObject {
@objc
func renderNaviDemo(_ originLat: NSNumber, oriLon originLon: NSNumber, oriName originName: NSString, destLat destinationLat: NSNumber, destLon destinationLon: NSNumber, destName destinationName: NSString) {
let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: originLat), longitude: CLLocationDegrees(truncating: originLon)), name: originName as String)
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: destinationLat), longitude: CLLocationDegrees(truncating: destinationLon)), name: destinationName as String)
let options = NavigationRouteOptions(waypoints: [origin, destination])
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
let navigationService = MapboxNavigationService(route: route, simulating: .never)
let navigationOptions = NavigationOptions(navigationService: navigationService)
let viewController = NavigationViewController(for: route, options: navigationOptions)
let appDelegate = UIApplication.shared.delegate
appDelegate!.window!!.rootViewController!.present(viewController, animated: true, completion: nil)
}
}
}
Now I get the error:
Contextual closure type '(Directions.Session, Result <RouteResponse,
DirectionsError>) -> Void' (aka '((options: DirectionsOptions,
credentials: DirectionsCredentials), Result <RouteResponse,
DirectionsError>) -> ()') expects 2 arguments , but 3 were used in
closure body
For example, if I remove the 'Error' argument I get the error:
Value of type 'Result <RouteResponse, DirectionsError>' has no member
'first'
My objective-c file looks like:
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(BasicViewController)
RCT_EXTERN_METHOD(renderNaviDemo:(nonnull NSNumber *)originLat oriLon:(nonnull NSNumber *)originLon oriName:(NSString *)originName destLat:(nonnull NSNumber *)destinationLat destLon:(nonnull NSNumber *)destinationLon destName:(NSString *)destinationName)
@end
And the bridge file like:
#ifndef bridging_Header_h
#define bridging_Header_h
#import "React/RCTBridgeModule.h"
#import "React/RCTViewManager.h"
#endif /* bridging_Header_h */
Is there a solution for this? thanks in advance