gpt4 book ai didi

ios - 触摸事件不适用于 cordova 应用程序的 ios 构建

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:03:21 34 4
gpt4 key购买 nike

我有一个非常简单的 cordova 应用程序,它是默认 cordova“设备就绪”模板的扩展。它有一个带有简单点击事件的按钮。

可以在此处看到在 iOS 模拟器上运行。

Simple Cordova app

下面是我项目的代码

index.html

<html>
<head>
<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>
<div class="app">
<h1>Simple App</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<button type="button" id="testBttn">Press me</button>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>

index.js

var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');

listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');

console.log('Received Event: ' + id);
}
};

app.initialize();

console.log('ready to test button');

document.getElementById("testBttn").addEventListener("click", function (){
console.log('button was pressed!');
});

我面临的问题是在模拟器上运行时按钮对任何点击(触摸手势)完全没有反应

当在浏览器中运行时,该按钮工作正常并输出到控制台

当我在模拟器上通过 XCode 而不是 CLI 运行应用程序时,我得到了相同的结果,尽管我在模拟器屏幕上单击 任意位置 后立即得到以下输出。

2016-10-13 00:16:57.738602 CordovaApp[14845:2773283] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-13 00:16:57.739331 CordovaApp[14845:2773283] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-10-13 00:16:57.741806 CordovaApp[14845:2773283] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0

此输出提供的信息很少,但可能表明一个明显的问题。在构建 native ios 应用程序时,我从未有过这种输出。

感谢任何帮助。

编辑:我正在使用 XCode 8.0

我提到这一点是因为在构建 ios 10 应用程序时,这种控制台输出在 XCode 8 中似乎很常见。从我能发现的情况来看,这个控制台输出似乎微不足道,没有什么不寻常的。

最佳答案

我今天突然发现同样的事情发生在我身上。我找到的唯一解决方案根本不是真正的解决方案,但是当我切换到另一个应用程序然后突然切换回我的应用程序时,触摸事件全部重新开始工作。但是刚打开的应用程序完全没有响应。所以不完全是解决方案,但看看您是否遇到相同的行为。

关于ios - 触摸事件不适用于 cordova 应用程序的 ios 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39997354/

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