在 React Native 中实现 Safari 视图控制器

Implement Safari View Controller in React Native

我们目前将我们的应用程序上传到苹果商店并得到以下答案:

We recommend implementing the Safari View Controller API to display web content within your app. The Safari View Controller allows the display of a URL and inspection of the certificate from an embedded browser in an app so that customers can verify the webpage URL and SSL certificate to confirm they are entering their sign in credentials into a legitimate page.

目前我正在使用此代码从我们的应用程序打开网站

Linking.openURL('here-goes-the-url')

所以我有点不知道苹果的这个答案到底是什么意思。我应该在我的应用程序中使用 WebView 来显示网站内容吗?我试过了,但是我看不到苹果评论中提到的任何 url 或证书。

到目前为止我发现的是这样的: https://www.npmjs.com/package/react-native-safari-view-controller

但是这个 repo 已经 2 年没有维护了。

有没有人能更清楚地说明审稿人的回答是什么意思? 我可以使用

WebBrowser.openBrowserAsync('url')

实现自己想要的?

此致

所以现在,通过使用 Linking.openURL...,您会将用户发送到外部浏览器(iOS 上的 safari)。

评论者希望您提供更好的用户体验,让您的用户继续使用您的应用,同时仍然为他们提供 safari 的所有功能。

要做到这一点,您必须使用一种叫做 Safari View Controller(在 iOS 上)的东西,这基本上就像在您的应用程序 打开 safari。

尽管 library you pointed to 确实做到了这一点,但它不再维护并且仅适用于 iOS,因此我会使用适用于 Android 的更现代的东西还有:

https://github.com/proyecto26/react-native-inappbrowser

expo-web-browser 提供对系统网络浏览器的访问并支持处理重定向。在 iOS 上,它使用 SFSafariViewControllerSFAuthenticationSession,具体取决于您调用的方法,在 Android 上它使用 ChromeCustomTabs。从 iOS 11 开始,SFSafariViewController 不再与 Safari 共享 cookie,因此如果您使用 WebBrowser 进行身份验证,则需要使用 WebBrowser.openAuthSessionAsync,如果你只是想打开一个网页(比如你的应用隐私政策),那么使用WebBrowser.openBrowserAsync

https://docs.expo.io/versions/latest/sdk/webbrowser/

示例代码参考:-

export default function App() {
  const [result, setResult] = useState(null);

  const _handlePressButtonAsync = async () => {
    let result = await WebBrowser.openBrowserAsync('https://expo.io');
    setResult(result);
  };
  return (
    <View style={styles.container}>
      <Button title="Open WebBrowser" onPress={_handlePressButtonAsync} />
      <Text>{result && JSON.stringify(result)}</Text>
    </View>
  );
}