Cordova应用程序在Android上工作,但线程似乎冻结ios"由于页面加载而重置插件"

时间:2016-04-08 12:26:28

标签: javascript ios cordova plugins

Cordova应用程序在Android上工作,但线程似乎冻结在ios上。使用iOS插件版本4.1.1的Cordova 6.1版。应用程序在Android模拟器和设备上运行良好。

从XCode app在设备上运行时似乎加载了。主屏幕显示正常,但我没有看到任何console.log语句应该出现在设备准备事件后,我点击手机上的主页按钮。然后立即出现连接到SQLite DB等的前几个函数的所有控制台日志语句。

正在使用的插件:

  • 科尔多瓦-插件控制台
  • 科尔多瓦-源码存储
  • flyacts-插件-barcodescanner

然后我可以再次点击启动器图标并与应用程序进行交互,但在我再次点击主页按钮之前,控制台中不会显示任何内容。在点击主页按钮让它运行之前,我无法排队多个数据库事务或一次调用我的条形码扫描器。

在deviceready之后调用的console.log消息没有出现,但是在应用程序中导航的代码确实运行,因为通过应用程序的导航工作。似乎只是插件被阻止了。

示例代码:

var app ={
  init: function(){
    document.addEventListener("deviceready", app.onDeviceReady);
  },
  onDeviceReady: function(ev){
    console.log("device ready"); //this does NOT appear in the console
    //add some click listeners to buttons for navigation
    //and this code DOES run
    console.log("another test message"); //does NOT appear
    app.setUpDB();
  },
  setUpDB: function(){
    console.log("setting up DB"); //this does NOT appear in console
    //code to open DB and create tables
    //this code will not run until after the home button clicked
  },
  ... more functions ...
}
app.init();
console.log("this won't appear before home button click");

在单击主页按钮之前在控制台中显示消息

2016-04-08 08:35:42.900 MeetCute-MadLib[387:141553] Apache Cordova native platform version 4.1.1 is starting.
2016-04-08 08:35:42.903 MeetCute-MadLib[387:141553] Multi-tasking -> Device: YES, App: YES
2016-04-08 08:35:43.000 MeetCute-MadLib[387:141553] Using UIWebView
2016-04-08 08:35:43.005 MeetCute-MadLib[387:141553] [CDVTimer][handleopenurl] 0.510991ms
2016-04-08 08:35:43.012 MeetCute-MadLib[387:141553] [CDVTimer][intentandnavigationfilter] 5.966008ms
2016-04-08 08:35:43.012 MeetCute-MadLib[387:141553] [CDVTimer][gesturehandler] 0.219047ms
2016-04-08 08:35:43.012 MeetCute-MadLib[387:141553] [CDVTimer][TotalPluginStartup] 8.069038ms
2016-04-08 08:35:43.451 MeetCute-MadLib[387:141553] Resetting plugins due to page load.
2016-04-08 08:35:43.807 MeetCute-MadLib[387:141553] Finished load of: file:///var/containers/Bundle/Application/2DC8233D-0BA4-4BE9-8689-53D492193E64/MeetCute-MadLib.app/www/index.html

然后......只要点击主页按钮,其余部分就会出现

2016-04-08 08:48:58.538 MeetCute-MadLib[391:143286] Initializing SQLitePlugin
2016-04-08 08:48:58.538 MeetCute-MadLib[391:143286] Detected docs path: /var/mobile/Containers/Data/Application/10EE751F-CE70-449E-800D-817371C9813E/Documents
2016-04-08 08:48:58.539 MeetCute-MadLib[391:143286] Detected Library path: /var/mobile/Containers/Data/Application/10EE751F-CE70-449E-800D-817371C9813E/Library
2016-04-08 08:48:58.539 MeetCute-MadLib[391:143286] no cloud sync at path: /var/mobile/Containers/Data/Application/10EE751F-CE70-449E-800D-817371C9813E/Library/LocalDatabase
2016-04-08 08:48:58.540 MeetCute-MadLib[391:143286] device is ready
2016-04-08 08:48:58.540 MeetCute-MadLib[391:143286] tagname a
2016-04-08 08:48:58.540 MeetCute-MadLib[391:143286] test the sqlitePlugin
2016-04-08 08:48:58.540 MeetCute-MadLib[391:143286] set up DB
2016-04-08 08:48:58.540 MeetCute-MadLib[391:143345] open full db path: /var/mobile/Containers/Data/Application/10EE751F-CE70-449E-800D-817371C9813E/Library/LocalDatabase/DBmeetcute
2016-04-08 08:48:58.584 MeetCute-MadLib[391:143286] THREAD WARNING: ['Console'] took '43.607910' ms. Plugin should use a background thread.
2016-04-08 08:48:58.589 MeetCute-MadLib[391:143286] about to openDatabase
2016-04-08 08:48:58.589 MeetCute-MadLib[391:143286] OPEN database: DBmeetcute
2016-04-08 08:48:58.589 MeetCute-MadLib[391:143286] database already open: DBmeetcute
2016-04-08 08:48:58.590 MeetCute-MadLib[391:143286] create the tables IF NOT EXISTS
2016-04-08 08:48:58.590 MeetCute-MadLib[391:143286] new transaction is waiting for open operation
2016-04-08 08:48:58.590 MeetCute-MadLib[391:143286] fetching profile
2016-04-08 08:48:58.590 MeetCute-MadLib[391:143286] new transaction is waiting for open operation
2016-04-08 08:48:58.596 MeetCute-MadLib[391:143345] Good news: SQLite is thread safe!
2016-04-08 08:48:59.237 MeetCute-MadLib[391:143286] DB opened: DBmeetcute

1 个答案:

答案 0 :(得分:1)

我能够获得@ prof3ssorSt3v3 index.html的副本。 CSP是不正确的,因为它缺少gap:,它允许JS和本机端进行通信。因此,如果您遇到类似这样的问题,请检查index.html中的CSP标记。

    <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 *">