簡體   English   中英

WebView (react-native-webview) 在 Expo SDK36 中獲取錯誤代碼 -1

[英]WebView (react-native-webview) getting error code -1 in Expo SDK36

我的 Expo 應用程序的 WebViewScreen 代碼:

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

export default WebViewScreen = () => (
    <WebView
        originWhitelist={['*']}
        source={{ uri: 'https://www.google.com' }}
    />
);

但是當我運行它時,我收到以下錯誤:

Encountered an error loading page, Object {
  "canGoBack": false,
  "canGoForward": false,
  "code": -1,
  "description": "net::ERR_CACHE_MISS",
  "loading": false,
  "target": 3,
  "title": "Web page not available",
  "url": "https://www.google.com/",
}

筆記:
我的 Android 手機已連接到 wifi,並且我幾乎可以在我的 Expo 應用程序的每個屏幕上使用后端服務器 API,這證實了Internet 可以訪問並且我的應用程序有權使用 internet

我的環境:
Android 三星手機(Android 版本 5.1.1),
EXPO SDK版本為36,
react-native-webview版本 8.0.6,
Expo 客戶端應用程序版本 2.14.0

PS:
對於react-native-webview
我沒有做npm install --save react-native-webview
相反,我使用expo-cli版本 3.11.7 expo install react-native-webview

PPS:我嘗試通過二維碼掃描從這里(官方?)在我的手機上運行 webview 的 expo 小吃,但得到了同樣的錯誤( "code": -1

有人可以指導如何擺脫這個錯誤並使 webview 啟動並運行嗎?

您是否在清單中設置了正確的權限?

<uses-permission android:name="android.permission.INTERNET"/>

在您的情況下,它應該是 App.json 文件

您是否嘗試過此處發布的臨時修復程序?

他們說網站服務人員可能有問題(由於 Chrome 75 中的錯誤)。

解決方案包括將此 JS 腳本注入WebView ,以取消注冊停滯的服務工作者:

navigator.serviceWorker.getRegistrations().then(function(registrations) {
    for (let registration of registrations) {
        registration.unregister();
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM