简体   繁体   English

科尔多瓦:警报未在桌面环境中显示(它们在模拟器和真实设备上均能正常工作)

[英]Cordova: Alerts not shown on desktop environment (They work fine on simulator and real device)

I am working on a pet project using Cordova. 我正在使用Cordova进行宠物项目。 At the moment, target platform is only IOS.During the development, I was using alerts land marks to ensure what I intended was actually happening.(Personally, I found, alerts are easier to work with in simple cases where as logs are much handy in complex scenarios). 目前,目标平台仅是IOS。在开发过程中,我一直在使用警报地标来确保我的意图确实在发生(我个人认为,在日志很方便的简单情况下,警报更容易使用在复杂的情况下)。 At some point in the code, I have a button and a function that gets executed when that button is clicked. 在代码中的某个时候,我有一个按钮和一个单击该按钮时会执行的函数。

Related cordova plugin is included, as you can see below the terminal output: 包含相关的cordova插件,如您在终端输出下面看到的那样:

cordova plugins
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-whitelist 1.3.3 "Whitelist"

I have tied up alert function into window object for convenience: 为了方便起见,我将警报功能绑定到窗口对象中:

document.addEventListener('deviceready', function () {
  console.log("deviceready");
  if (navigator.notification) { 
      window.alert = function (message) {
          navigator.notification.alert(
              message,    // message
              null,       // callback
              "My Awesome App", // title
              'OK'        // buttonName
          );
      };
      startApp();  // This is the kick off point for my app
  }
}, false);

UPDATE 3 : I suspect that above window.alert assignment is bugging things up. 更新3 :我怀疑在window.alert分配上面正在调试东西。 If I comment out this assignment, regular alerts works as expected (but they look ugly). 如果我注释掉此作业,则常规警报会按预期工作(但看起来很丑)。 Does anyone see anything suspicious with this usage? 有人看到这种用法有可疑之处吗?

In the startApp function, I have the following line to bind the click event to the button: 在startApp函数中,我有以下代码行将click事件绑定到按钮:

$('#startActionButton').on('click', {name: 'this is really not need'}, someView.startAction);

My startAction function lives in a View class and defined as: 我的startAction函数位于View类中,并定义为:

this.startAction = function(event){
    window.alert('Starting Action');
    console.log('Starting Action');
}

This code works perfectly fine on IOS simulator and on a real IOS device. 此代码在IOS模拟器和真实的IOS设备上都可以正常工作。 However, it is time consuming to deploy the code each and everytime to either platforms. 但是,每次都将代码部署到任何一个平台都非常耗时。 So, I prefer to develop on responsive desktop environment for the most part, and then do a detailed testing in either simulator or real device at the end of each development cycle. 因此,我更喜欢在响应式桌面环境中进行开发,然后在每个开发周期结束时在模拟器或真实设备中进行详细的测试。

So, when I ran the application in desktop environment with: 因此,当我在桌面环境中使用以下命令运行该应用程序时:

cordova serve

I do see that Starting Action in the console log. 确实在控制台日志中看到了“ 启动操作” However, I do not get the alert.! 但是,我没有收到警报。

Here are my questions. 这是我的问题。

  1. Does anyone have any idea why it would be? 有谁知道为什么会这样吗?
  2. I debugged the code, and put a break point in the startAction function, on the line of alert function. 我调试了代码,并在警报功能行的startAction函数中放置了一个断点。 There, in debugger window, I typed the following and got the responses as below: 在调试器窗口中,我输入了以下内容,并得到如下响应:

window.alert是已定义的还是未定义的? WTH ??

Any idea how come is window.alert undefined although I can confirm that it exists and it has the correct source code? 尽管我可以确认window.alert存在并且具有正确的源代码,但不确定如何定义window.alert吗?

This is not a road blocker problem for me, as I can live with console.logs but I am just curious, why alerts are failing to work on desktop environment. 对我来说,这不是一个路障问题,因为我可以使用console.logs,但是我很好奇,为什么警报无法在桌面环境下工作。 Is there any known bug in Cordova code? Cordova代码中是否存在任何已知的错误? Am I missing anything? 我有什么想念的吗? Just curious. 只是好奇。

Any insight would be highly appreciated. 任何见解将不胜感激。

PS: I would like to add before asked that I also removed and re-installed the notifications plugin. PS:我想补充一下,然后问我是否也删除并重新安装了通知插件。 But it did not help the case. 但这对案件没有帮助。

PS2: Version of cordova I am using is: PS2:我使用的cordova版本是:

cordova -version
8.0.0

UPDATE 1 I forgot to add, I am also using ratchet.css (not js) for formatting, although I believe it has nothing to do with it. 更新1我忘了添加,我也使用ratchet.css(不是js)进行格式化,尽管我认为这与它无关。

UPDATE 2 Asked by @Gandhi, I have cordova.js included in my index.html 更新2 @Gandhi询问,我的index.html中包含cordova.js

UPDATE 4 I renamed the custom alert as follows: 更新4我重命名了自定义警报,如下所示:

  window.myalert = function (message) {
      navigator.notification.alert(
          message,    // message
          null,       // callback
          "My Awesome App", // title
          'OK'        // buttonName
      );
  };

Now I can confirm that regular JS alerts work whereas this custom myalert still does not. 现在,我可以确认常规JS警报起作用,而此自定义myalert仍然不能起作用。

The primary intent of the OP is to develop and test the app in desktop environment so that the turn around time is quick. OP的主要目的是在桌面环境中开发和测试应用程序,以便缩短周转时间。 Once the application is tested in desktop environment, it can be ported to iOS simulator for further testing. 一旦在桌面环境中测试了应用程序,就可以将其移植到iOS模拟器中进行进一步测试。

The 'browser' platform in cordova is tailor made for this requirement which helps in testing the app using browser like Chrome. Cordova的“浏览器”平台是针对此要求量身定制的,有助于使用Chrome等浏览器测试应用。 You can check out the following link for more info on browser platform. 您可以查看以下链接以获取有关浏览器平台的更多信息。 Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Browserify JavaScript库在iOS模拟器上运行良好,但在真实设备上 - Browserify javascript library work well on iOS simulator but real device 如何确定我的Cordova应用程序是在模拟器还是真实设备上运行? - How can I tell if my Cordova application is running on a simulator or real device? 声音文件在带有LibGDX的桌面上运行良好,但在Android设备上崩溃 - Sound file runs fine on Desktop with LibGDX, but crashes on android device HTML 按钮在桌面上正常工作 在移动设备上不起作用 - HTML buttons work fine on desktop do not work on mobile 为什么我的应用程序在我的 android 仿真器上运行良好,但在我的真实 android 设备上运行不正常 - Why my app is working fine on my android emulator but its not working fine on my real android device 为什么 javascript 在 RN webview 中不起作用,但桌面浏览器工作正常? - Why does javascript not work in RN webview but desktop browser works fine? iPad中的Jquery Slider问题,可在台式机和笔记本电脑上正常工作 - Jquery Slider issue in iPad which work fine in desktop and laptop 响应式设计可在桌面浏览器,移动模拟器(Safari和Mozilla Firefox)上运行,但不能在真正的智能手机(Android,iOS)上运行 - Responsive design working on desktop browser, on mobile-simulator (both Safari and Mozilla Firefox), but not on a real smartphone (Android, iOS) 按钮在桌面上工作,调整为移动设备,但在真正的移动设备上没有反应 - Button work on desktop, resized to mobile but dont react on real mobile 用于Apache Cordova的JavaScript代码在模拟器Ripple上运行,但不在Live Windows Phone设备中运行(L 535) - javascript code for apache Cordova working on simulator Ripple but not in Live windows phone Device (L 535)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM