I would like to launch mapbox navigation turn by turn through react native
(0.59.10
). when i do it without parameters (through an obj-c bridge and then a method defined in swift ) its works PERFECTLY . (parameters are defined in the swift function) .
when i want to send parameters(WITH ONE STRING JUST TO TRY IF IT WILL BE RECEIVED CORRECTLY) from react native its not working and i get this error :
Exception 'takeMeToWH' : is not recognized . Objective -c method'. was thrown while invoking 'takeMeToWH' on target RNMapBoxRNIos with params(heloo)
I am relatively new in react . i use xcode 11.2.1 and swift 5 Here is my code :
js file :
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,TouchableOpacity,NativeModules} from 'react-native';
export default class App extends React.Component{
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={()=>NativeModules.RNMapBoxRNIos.takeMeToWH("heloo")}>
<Text>Press</Text>
</TouchableOpacity>
</View>
);
}
}
obj-c file :
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_REMAP_MODULE(RNMapBoxRNIos, MapBoxRNIos, NSObject)
RCT_EXTERN_METHOD(takeMeToWH:(NSString *)name)
@end
swift file :
import Foundation
import UIKit
import MapboxDirections
import MapboxCoreNavigation
import MapboxNavigation
@objc(MapBoxRNIos)
class MapBoxRNIos: NSObject {
var navigateButton:UIButton!
@objc
func takeMeToWH(_name:NSString) {
print(_name)
let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.9131752, longitude: -77.0324047), name: "Mapbox")
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.8977, longitude: -77.0365), name: "White House")
let options = NavigationRouteOptions(waypoints: [origin, destination])
// addButton()
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
let viewController = NavigationViewController(for: route)
let appDelegate = UIApplication.shared.delegate
appDelegate!.window!!.rootViewController!.present(viewController, animated: true, completion: nil)
}
}```