开发者社区> 问答> 正文

无法使用参数桥接反应本机项目和iOS项目(Mapbox导航)

我想要启动Mapbox导航react native (0.59.10)。当我在没有参数的情况下(通过obj-c桥,然后是一个用Swive定义的方法)完成它的工作。(参数在FAST函数中定义)。当我想发送参数(用一个字符串来尝试是否会正确地接收到它)时,从本机响应它不起作用,我得到了这个错误:

异常‘takMeToWH’:未被识别。目的-C法。在使用params调用目标RNMapBoxRNIos上的“takMeToWH”时抛出(Heloo)

我的反应相对较新。我使用Xcode 11.2.1和Swive 5--这里是我的代码:

JS文件:

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

展开
收起
游客5akardh5cojhg 2019-12-09 13:22:52 632 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载