触摸事件不适用于cordova 应用程序的ios 版本 [英] Touch events not working on ios build of cordova app
问题描述
我有一个非常简单的cordova应用程序,它是默认cordova设备就绪"模板的扩展.它有一个按钮,附带一个简单的点击事件.
在这里可以看到在 iOS 模拟器上运行.
以下是我的项目代码
index.html
<头><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>头部><身体><div class="app"><h1>简单应用</h1><div id="deviceready" class="blink"><p class="事件监听">连接到设备</p><p class="接收到事件">设备准备就绪</p>
<button type="button" id="testBttn">按我</button>
<script type="text/javascript" src="cordova.js"></script><script type="text/javascript" src="js/index.js"></script></html>
index.js
var app = {//应用程序构造器初始化:函数(){this.bindEvents();},//绑定事件监听器////绑定启动时需要的任何事件.常见事件有://加载"、设备就绪"、离线"和在线".绑定事件:函数(){document.addEventListener('deviceready', this.onDeviceReady, false);},//设备就绪事件处理程序////'this' 的作用域是事件.为了调用'receivedEvent'//函数,我们必须显式调用 'app.receivedEvent(...);'onDeviceReady:函数(){app.receivedEvent('deviceready');},//在收到的事件上更新 DOM接收事件:函数(ID){var parentElement = document.getElementById(id);var listenElement = parentElement.querySelector('.listening');var receivedElement = parentElement.querySelector('.received');listenElement.setAttribute('style', 'display:none;');receivedElement.setAttribute('style', 'display:block;');console.log('收到的事件:' + id);}};app.initialize();console.log('准备测试按钮');document.getElementById("testBttn").addEventListener("click", function (){console.log('按钮被按下了!');});
我面临的问题是按钮在模拟器上运行时对任何点击(触摸手势)完全没有响应
在浏览器中运行时按钮工作正常并输出到控制台
当我在模拟器上通过 XCode 而不是 CLI 运行应用程序时,我得到了相同的结果,尽管我在模拟器屏幕上单击 anywhere 后立即得到以下输出.
2016-10-13 00:16:57.738602 CordovaApp[14845:2773283] 子系统:com.apple.UIKit,类别: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: 02016 年 10 月 13 日 00:16:57.739331 CordovaApp[14845:2773283] 子系统:com.apple.UIKit,类别:手势,enable_level:0,persist_level:0,default_ttl:1,info_ttl:0:debug,generate_ttl0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 02016 年 10 月 13 日 00:16:57.741806 CordovaApp[14845:2773283] 子系统:com.apple.UIKit,类别:GestureExclusion,enable_level:0,persist_level:0,default_ttl:1,info_ttltt:0:sympt0,s_sympt00, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
此输出提供的见解很少,但可能表明存在明显问题.在构建本机 ios 应用程序时,我从未有过这种输出.
感谢任何帮助.
我使用的是 XCode 8.0
我提到这一点是因为在构建 ios 10 应用程序时,这种控制台输出似乎在 XCode 8 中很常见.据我所知,这个控制台输出似乎微不足道,没什么特别的..
我今天突然发现同样的事情发生在我身上.我找到的唯一解决方案根本不是真正的解决方案,但是当我切换到不同的应用程序然后突然切换回我的应用程序时,触摸事件都重新开始工作.但是一个新打开的应用程序完全没有响应.所以不完全是一个解决方案,但看看您是否遇到相同的行为.
I have a very simple cordova app that is an extension of the default cordova 'device ready' template. It has one button with a simple click event attached.
as can be seen here running on an iOS simulator.
The following is the code of my project
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!');
});
The problem I am facing is that the button is completely unresponsive to any click (touch gesture) when running on the simulator
The button works fine and outputs to console when run in a browser
When I run the app through XCode on the simulator instead of the CLI I get the same result although I get the following output as soon as I click anywhere on the simulator screen.
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
This output offers little insight but may indicate an obvious issue. I have never had this output when building native ios applications.
Any help appreciated.
Edit: I am using XCode 8.0
I mention this as it appears this kind of console output is quite common in XCode 8 when building ios 10 apps. It seems from what I can find that this console output is trivial and is nothing out of the ordinary..
I have found the same thing happening to me today all of a sudden. The only solution that I have found isn't really a solution at all but when I switch to a different app and then switch back to my app suddenly the touch events all start working again. But a freshly opened app is completely unresponsive. So not exactly a solution but see if you experience the same behaviour.
这篇关于触摸事件不适用于cordova 应用程序的ios 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!