为什么 iOS 上的反应本机 webview 中的 iframe 不呈现内容?

Why is the iframe within a react native webview on iOS not rendering content?

我有一个 ReactNative 应用程序,它只使用 webview 来显示我们的 React 网站。我们的网站允许用户查看电子邮件,为了正确呈现这些电子邮件,我们使用了 iframe。所以我们的 iframe 看起来像这样:

<iframe className={'email-view-body-iframe'} srcDoc={pViewMessage.body}/>

其中 srcDoc 是要查看的邮件正文,可以是纯文本、旧版 rtf 邮件或 html 邮件。它在所有平台上都按预期工作,除了 iOS.

我浏览了 webview 文档,没有看到任何让我印象深刻的东西,我知道 iframe 在那里,因为我用一个奇怪的彩色背景设计了它,这样我就可以检查它是确实在正确的地方呈现。

有人能指出我正确的方向吗?

要显示静态 HTML 或内联 HTML,您需要将 originWhiteList 设置为 *

import { WebView } from 'react-native-webview'; 

class MyInlineWeb extends Component { 
  render() { 
    return ( 
      <WebView 
        originWhitelist={['*']} 
        source={{ html: '<h1>Hello    world</h1>' }} /> 
    ); 
  } 
} 

与上面的示例类似,您可以在 WebView 中加载 iFrame。

import { WebView } from 'react-native-webview'; 

class MyInlineWeb extends Component { 
  render() { 
    return ( 
      <WebView 
        originWhitelist={['*']} 
        source={{ html: "<iFrame src='your_URL' />" }} /> 
    ); 
  } 
}

因此,如上例所示,您的 iFrame 已加载到 WebView 组件中。然后,您可以在 iFrame 中呈现任何网页或 URL。