Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deviceready only fire after 30 seconds in iOS 10

I deviceready doesn't fire or fires very late in my ionic app when I run it on my iOS device with

ionic run ios --device -lcs

I removed all the plugins with ionic plugin rm ..., deleted the content of the plugins/ directory and reinstalled them. I also removed and reinstalled the ios platform with ionic platform rm/add ios.

I am stuck with this.

The iPhone (6+) is on iOS 10.

I am using ionic 1, and the last ionic CLI.

EDIT: I removed all plugins one by one, and its seems that the problem is due to cordova-plugin-network-information and cordova-plugin-device.

Process 663 detached
(lldb) 
(node:26790) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.

14    030280   warn     Native: deviceready did not fire within 2000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
15    030605   info     [object Object]
16    033286   log      deviceready has not fired after 5 seconds.
17    033290   log      Channel not fired: onCordovaInfoReady
18    033293   log      Channel not fired: onCordovaConnectionReady
19    363977   log      DEVICE READY FIRED AFTER, 32259, ms

My run.js, AppCtrl.js and the controller of my main view are encapsultaed in $ionicPlatform.ready(function () {..});`

My content security policy is:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; connect-src 'self' 'unsafe-inline' 'unsafe-eval' blob: ws: *;">
like image 755
Louis Avatar asked Dec 02 '16 16:12

Louis


2 Answers

I added Thanks for your response @baviskarmitesh. But I had to add gap to the content security policy and now it seems to work.

I added data: gap: https://ssl.gstatic.com 'unsafe-eval'after default-src * into my content security policy in my index.html file, like this:

<meta http-equiv="Content-Security-Policy" content="
  default-src * data: gap: https://ssl.gstatic.com 'unsafe-eval';
  style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
  script-src 'self' 'unsafe-inline' 'unsafe-eval' *;
  connect-src 'self' 'unsafe-inline' 'unsafe-eval' blob: ws: *;
">

And now deviceready fires quickly with all my plugins.

like image 96
Louis Avatar answered Nov 09 '22 14:11

Louis


This seems to be a common issue with Ionic framework and there could be multiple reasons for it. One reason could be some issue with the plugin you use or could also be due to some issue in the platform folder. There seems to be an open issue on this in Ionic CLI project.

Following could be the possible fixes for this issue:

  1. Removing the faulty plugins and re-adding the same
  2. Removing the platform folder and re-adding the same.
  3. Probably avoid using live reload option
  4. If the problem is iOS specific, then you can try relaxing the content security policy

You can also have a look at this link

Hope this should help.

like image 27
Gandhi Avatar answered Nov 09 '22 15:11

Gandhi