Cordova iOS不响应touchinput [英] Cordova iOS don't respond to touchinput

查看:180
本文介绍了Cordova iOS不响应touchinput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS上创建了Cordova应用程序,当我尝试按下模拟器上的按钮或真实设备上时,应该向我显示该按钮已按下的警报。不幸的是没有发生什么,我不知道为什么。一些代码:

I have created a Cordova app on iOS and when I try to press the button on the simulator or on a real device is is supposed to show me an alert that the button has been pressed. Unfortunately nothing happens and I'm not quite sure why. Some code:

<html>
<head>
    <!--
    Customize this policy to fit your own app's needs. For more guidance, see:
        https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
    Some notes:
        * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
        * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
        * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
            * Enable inline JS: add 'unsafe-inline' to default-src
    -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">

    <title>Hello World</title>
</head>
<body>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
    document.addEventListener('deviceready', function(){alert('device ready');}, false);

    function showAlert(){
        alert("Button is pressed!");
    }

</script>

<h1>This is an app</h1>
<button onClick="showAlert()">Press me!</button>

</body>

做一个令人难以置信的愚蠢的错误?

Can someone see if I am doing an incredible stupid mistake?

推荐答案

如果你使用5.0.0或更高版本, $ c>白名单系统。它包含 CSP (内容安全策略),防止inline-javascript工作。

If you are using 5.0.0 or higher, you are required to use the whitelist system. It covers CSP (Content Security Policy), which prevents inline-javascript from working.

您的HTML元素< button onClick =showAlert()>按下我!< / button> 有一个 inline-javascript 元素。您不能使用Cordova 5.0.0。该限制是新的WebView库( UIWebview WKWebview iOS )的一部分

Your HTML element <button onClick="showAlert()">Press me!</button> has an inline-javascript element. You canNOT use that as of Cordova 5.0.0. The restriction is part of the new WebView Library (UIWebview and WKWebview for iOS)

要在HTML中使用 inline-javascript ,您必须编写CSP异常。注意:这会让您的应用程式不安全

To use the inline-javascript in your HTML you will have to write a CSP exception. NOTE: This will make your app insecure. You can add security by following the link just below.

以下是您的代码,将其添加到您的 index.html

< meta http-equiv =Content-Security-Policy
content =default-src *;
style-src'self ''unsafe-inline''unsafe-eval';
script-src'self''unsafe-inline''unsafe-eval';>

Here is your code, add it to your index.html <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-inline' 'unsafe-eval';">

以下链接将帮助指导您完成所需的操作:

如何应用Cordova / Phonegap白名单系统

Best of Luck

The following link will help guide you through what you need:
HOW TO apply the Cordova/Phonegap the whitelist system
Best of Luck

这篇关于Cordova iOS不响应touchinput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆