1. 下載組件 npm install react-native-webview-bridge --savejava
2. 自動連接庫 react-native link react-native-webview-bridge react
3. 由於組件比較老,須要作改變引用頭文件的方式,將組件全部的引用頭文件都參考如下修改:(參考連接http://reactnative.cn/post/3277)web
例:#import <React/RCTView.h>
#import <UIKit/UIKit.h>
#import <React/RCTAutoInsetsProtocol.h>
#import <React/RCTConvert.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
#import <React/RCTView.h>
#import <React/UIView+React.h>
#import <objc/runtime.h>
4. 在h5頁面中引用webviewbridge.js,在點擊事件中調用:npm
WebViewBridge.send(url)
5. 在React Native中接收:react-native
import WebViewBridge from 'react-native-webview-bridge'; .... onBridgeMessage(message) { const { webviewbridge } = this.refs; console.log('receiving message.....',message); this.props.nav.push({ component: Ad, title: '優惠商戶', passProps:{ data:message, } }); } .... render(){ ... <WebViewBridge ref="webviewbridge" onBridgeMessage={this.onBridgeMessage.bind(this)} javaScriptEnabled={true} source={{uri: this.state.url, method: 'GET'}} style={{width: width, height:320,}} bonces={true} startInLoadingState={false} scalesPageToFit={true}/> .... }