android - 有没有更好的方法从 React Native 打开 vcf 文件除了 Linking

标签 android ios react-native react-native-ios

当我尝试时:

Linking.openURL("....vcf");

我的应用程序打开浏览器并显示具有指定 vcf 的联系人。
有没有办法在不首先移动到浏览器的情况下在 native react 和打开 vcf 中避免这种情况?

最佳答案

您可以使用以下库 react-native-inappbrowser

按照github页面安装

import { Linking } from 'react-native'
import InAppBrowser from 'react-native-inappbrowser-reborn'

...
  async openLink() {
    try {
      const url = '...vcf'
      if (await InAppBrowser.isAvailable()) {
        const result = await InAppBrowser.open(url, {
          // iOS Properties
          dismissButtonStyle: 'cancel',
          preferredBarTintColor: '#453AA4',
          preferredControlTintColor: 'white',
          readerMode: false,
          animated: true,
          modalPresentationStyle: 'overFullScreen',
          modalTransitionStyle: 'partialCurl',
          modalEnabled: true,
          // Android Properties
          showTitle: true,
          toolbarColor: '#6200EE',
          secondaryToolbarColor: 'black',
          enableUrlBarHiding: true,
          enableDefaultShare: true,
          forceCloseOnRedirection: false,
          // Specify full animation resource identifier(package:anim/name)
          // or only resource name(in case of animation bundled with app).
          animations: {
            startEnter: 'slide_in_right',
            startExit: 'slide_out_left',
            endEnter: 'slide_in_left',
            endExit: 'slide_out_right'
          },
          headers: {
            'my-custom-header': 'my custom header value'
          },
          waitForRedirectDelay: 0
        })
        Alert.alert(JSON.stringify(result))
      }
      else Linking.openURL(url)
    } catch (error) {
      Alert.alert(error.message)
    }
  }
...

可以查看the example app here

关于android - 有没有更好的方法从 React Native 打开 vcf 文件除了 Linking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58118325/

相关文章:

ios - swift ,将单选按钮组添加到 TableView 单元格

ios - 以编程方式阻止 iOS 应用程序中的来电显示

react-native - 如何在 react-native (expo) 中从 OTG 输入读取视频流 - 降低帧速率,转换为灰度并显示它?

ios - 如何在 React Native 中实现 PageCurl(翻页)转换

Android:EditText 中的字符数有限

android - 如何使用 OkHTTP 测量下载速度?

ios - TabBarItem 上的角标(Badge)

javascript - 每次操作后 Redux Store 都会被清除

java - Firebase RecyclerView 显示一项

android - 如何在 XML 布局(或编程)中扩展 XWalkView?