如何从React Native iOS应用中调用Bluefy浏览器?
在React Native iOS中调用Bluefy浏览器的URL Scheme
Bluefy对应的自定义URL Scheme是bluefy://。
你可以通过React Native的Linking组件结合该Scheme启动Bluefy并打开指定网页,示例代码如下:
import { Linking } from 'react-native'; const openUrlInBluefy = async (targetUrl) => { // 构造Bluefy可识别的URL格式 const bluefyDeepLink = `bluefy://${targetUrl.replace(/^https?:\/\//, '')}`; const isSupported = await Linking.canOpenURL(bluefyDeepLink); if (isSupported) { await Linking.openURL(bluefyDeepLink); } else { console.log('设备未安装Bluefy浏览器'); } }; // 调用示例:打开目标蓝牙通信网页 openUrlInBluefy('https://your-bluetooth-webpage.com');
另外需要在iOS项目的Info.plist中添加Bluefy的Scheme到LSApplicationQueriesSchemes数组,否则canOpenURL会返回false:
<key>LSApplicationQueriesSchemes</key> <array> <string>bluefy</string> </array>
内容的提问来源于stack exchange,提问作者34n
相关产品推荐
相关产品推荐

