我想从我的webview打开谷歌地图应用程序中的谷歌地图链接。当链接在外部浏览器中打开,然后转到谷歌地图时,可能吗?
这是我正在使用的代码
<WebView
source={{ uri: "https://reactnative.dev" }}
ref={this.WEBVIEW_REF}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
/>
我在打开邮件应用程序时遇到了类似的问题。我找到了这个github线程https://github.com/react-native-webview/react-native-webview/issues/1084在那里我意识到我必须用CCD_ 2替换CCD_。现在mailto:链接打开设备上的邮件应用程序,但不在模拟器中(模拟器上没有安装邮件应用程序(。
要支持内置url方案之外的更多深度链接url,请遵循本指南https://reactnative.dev/docs/linking
从Webview打开谷歌地图应用程序中的谷歌地图链接的最佳方法是使用"onShouldStartLoadWithRequest"道具。
别忘了:
import {Linking} from 'react-native';
代码:
<WebView
source={{ uri: "https://reactnative.dev" }}
onShouldStartLoadWithRequest={event => {
if (event.url.match(/(goo.gl/maps)|(maps.app.goo.gl)/) ) {
Linking.openURL(event.url)
return false
}
return true
}}
/>
阅读更多关于"onShouldStartLoadWithRequest"道具来自文档