Cordova plugins only work in iOS the second time its opened with a THREAD WARNING. How do you get plugins to initialize onload?

…衆ロ難τιáo~ 提交于 2019-11-29 15:15:13

问题


Cordova Plugins in my iOS application only work after you open the app, close it by going back to the home screen, then reopening the app. Then a THREAD WARNING displays in the XCode log.

2014-05-14 14:00:38.062 TLEMobile[28819:60b] THREAD WARNING: ['InAppBrowser'] took '192.306885' ms. Plugin should use a background thread.
2014-05-14 14:01:18.919 TLEMobile[28819:60b] THREAD WARNING: ['Notification'] took '39.698975' ms. Plugin should use a background thread.

What is causing this? And if I really need to set all the plugins as background threads how do you set that?

I have added this param to my config.xml for ios to force the plugin to load on open but that doesn't seem to work.

<param name="onload" value="true" />

I simply do not get it. I have tried reinstalling the platform as a whole. Individually removing all the plugins and putting them back and I am still getting the same issue. Plugins will only work when the app gets backgrounded and then brought back up. Here is the code from the recent build to ios as I start the app. It appears that the plugins load as th is starts but then are not accessible.

2014-05-22 15:39:40.817 TLEMobile[5199:60b] Multi-tasking -> Device: YES, App: YES
2014-05-22 15:39:40.875 TLEMobile[5199:60b] Unlimited access to network resources
2014-05-22 15:39:41.131 TLEMobile[5199:60b] [CDVTimer][device] 0.559986ms
2014-05-22 15:39:41.136 TLEMobile[5199:60b] [CDVTimer][notification] 0.389040ms
2014-05-22 15:39:41.143 TLEMobile[5199:60b] [CDVTimer][inappbrowser] 3.835022ms
2014-05-22 15:39:41.149 TLEMobile[5199:60b] [CDVTimer][socialsharing] 1.318038ms
2014-05-22 15:39:41.153 TLEMobile[5199:60b] [CDVTimer][TotalPluginStartup] 23.202002ms
2014-05-22 15:39:41.659 TLEMobile[5199:60b] Resetting plugins due to page load.
2014-05-22 15:39:41.664 TLEMobile[5199:60b] IAB.close() called but it was already closed.
2014-05-22 15:39:45.843 TLEMobile[5199:60b] Finished load of: file:///var/mobile/Applications/220DD603-0644-4290-AE21-F9B6041D8408/TLEMobile.app/www/index.html#/tab/home
2014-05-22 15:39:54.914 TLEMobile[5199:60b] THREAD WARNING: ['Device'] took '14.032959' ms. Plugin should use a background thread.
2014-05-22 15:39:55.033 TLEMobile[5199:60b] THREAD WARNING: ['Notification'] took '100.118896' ms. Plugin should use a background thread.
2014-05-22 15:40:00.716 TLEMobile[5199:60b] THREAD WARNING: ['Notification'] took '5541.863037' ms. Plugin should use a background thread.

回答1:


I had same issue. Today I've found solution for my case.

The problem was with js2native bridge. Cordova has different methods to communicate with native library (bridge mode):

  • XHR with, w/o or optional payload;
  • iframe hash with or w/o payload;
  • iframe nav.

In cordova.js you can find iOSExec function. For iOS (except iOS 5) bridge mode is set to IFRAME_NAV.

Previous developer made couple of mistakes when on project design phase - and one of them is that whole content is removed from when view changes. And cordova's too. So cordova gets some error loops and plugins is not working.

The solution is to force XHR bridge mode. I've inserted next code right in my deviceready callback:

cordova.exec.setJsToNativeBridgeMode(cordova.exec.jsToNativeModes.XHR_NO_PAYLOAD);

I hope this will help you. Good luck.




回答2:


I had the same symptoms on cordova-ios 3.9.2 but my root cause was different from others listed here. Turns out it was a content security policy issue, gap://ready is required for the iframe cordova bridge.

If none of the other solutions work for you, look at your content security policy and make sure to add gap: to the frame-src part of your <meta http-equiv="Content-Security-Policy" tag.

Note: Xcode doesn't show any clue to fix this error but safari debugging shows the error very clearly.



来源:https://stackoverflow.com/questions/23662121/cordova-plugins-only-work-in-ios-the-second-time-its-opened-with-a-thread-warnin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!