gpt4 book ai didi

cordova - Ionic 2 : Cordova is not available. 确保包含 cordova.js 或在设备/模拟器中运行(在模拟器中运行)

转载 作者:行者123 更新时间:2023-12-03 06:03:27 31 4
gpt4 key购买 nike

我刚刚设置了我的第一个 ionic 2 应用程序(我相当广泛地使用了 ionic 1)。我正在尝试使用 ionic-native camera预览插件。

设置非常简单:

npm install -g ionic cordova
ionic start timesnap --v2
ionic platform add android
ionic platform add ios
ionic plugin add cordova-plugin-camera-preview --save

然后我将示例代码复制并粘贴到“关于”页面中:

import { CameraPreview, CameraPreviewRect } from 'ionic-native';

// camera options (Size and location)
let cameraRect: CameraPreviewRect = {
x: 100,
y: 100,
width: 200,
height: 200
};


// start camera
CameraPreview.startCamera(
cameraRect, // position and size of preview
'front', // default camera
true, // tap to take picture
false, // disable drag
true, // send the preview to the back of the screen so we can addoverlaying elements
1 //alpha
);

我使用以下命令启动了该应用:

ionic emulate android -lcs

ionic emulate ios -lcs --target='iPhone-6'

起初相机没有出现,然后我运行 chrome://inspect 并看到有关 Cordova 缺少“尝试在模拟器中运行”的警告,但这是在 Android 中运行时模拟器。我也尝试过 iOS,并看到了相同的结果。

有什么想法为什么 Cordova 无法加载吗?

以下是在 Android 模拟器中运行时来自 chrome://inspect 的完整错误日志:

enter image description here

更新...index.html

(这只是ionic生成的标准)

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ionic App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">

<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#4e8ef7">

<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>

<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->

<link href="build/main.css" rel="stylesheet">

</head>
<body>

<!-- Ionic's root component and where the app will load -->
<ion-app class="trans"></ion-app>

<!-- The polyfills js is generated during the build process -->
<script src="build/polyfills.js"></script>

<!-- The bundle js is generated during the build process -->
<script src="build/main.js"></script>

</body>
</html>

最佳答案

这已经很晚了,但遇到同样问题的任何人都可能会从此答案中受益。首先尝试通过运行以下命令来添加浏览器ionic platform add browser,然后运行命令ionic run browser

which is the difference between ionic serve and ionic run browser?

Ionic serve - runs your app as a website (meaning it doesn't have any Cordova capabilities). Ionic run browser - runs your app in the Cordova browser platform, which will inject cordova.js and any plugins that have browser capabilities

您可以引用this link了解 ionicserveionic run browser 命令之间的更多区别

更新

从 Ionic 3 开始,此命令已更改。请改用下面的命令;

ionic cordova平台添加浏览器

ionic cordova 运行浏览器

您可以通过运行以下命令了解您正在使用的 ionic 版本:ionic --version

关于cordova - Ionic 2 : Cordova is not available. 确保包含 cordova.js 或在设备/模拟器中运行(在模拟器中运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40815183/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com