我想要启动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)
}
}```
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。