Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

Unable to bridge React native project and ios Project(mapbox navigation) with parameters

$
0
0

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)
    }
  }```

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>