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

Deadly 提交于 2019-11-30 10:07:42

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.

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.

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