Search code examples
javascriptioscordovaphonegap-pluginsphonegap-pushplugin

Cordova only executes plugins after resume event


I'm using Cordova 3.5.0 on iOS.

My application loads, the 'deviceReady' event is fired, but no plugin actions are executed until I put my app in the background (by going to the homescreen).

When I go back into my app, the 'resume' handler gets fired, logs show up in LLDB and the PushNotification plugin starts listening to events and tries to register push notifications.

Why does this only happen once I have put my app to sleep?

These are the installed plugins (cordova plugins ls):

com.patrickheneise.cordova.statusbar 0.0.2 "Status Bar"
com.phonegap.plugins.PushPlugin 2.2.1 "PushPlugin"
com.phonegap.plugins.actionsheet 1.0.0 "ActionSheet"
org.apache.cordova.console 0.2.10-dev "Console"
org.apache.cordova.dialogs 0.2.9-dev "Notification"
org.apache.cordova.vibration 0.3.10-dev "Vibration"

Thanks in advance.


Solution

  • I had the same problem in my own app with cordova 6.3.0. After dozens of tests I found the problem.

    I had a Content-Security-Policy meta-tag defined like this:

    <meta http-equiv="Content-Security-Policy" content="default-src *;
          style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 
         'unsafe-eval'; media-src *">
    

    It turns out default-src * is not enough.

    With the following policy it works:

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

    The key part here ist the gap:

    It seems to be required, to properly execute cordova plugin code on iOS. But I still find it strange that the policy is influenced by resuming to the app.

    Additional note: the problem seems to affect all plugins that are displayed outside the webview. I had it with cordova-plugin-camera, phonegap-plugin-barcodescanner, cordova-plugin-dialogs. Other plugins like cordova-plugin-file-transfer worked just fine.