[ 
https://issues.apache.org/jira/browse/CB-12815?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Rich Storm updated CB-12815:
----------------------------
    Description: 
iOS 10 now has power saving requirements and will not allow background tasks to 
function to save battery. For example, a VoIP app can no longer use a polling 
strategy to stay awake. The new recommended way, according to Apple 
(https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html),
 is to use VoIP silent push notifications to wake up the app and do the work. 

I have verified that all VoIP silent push notifications arrive correctly when 
using the UIWebView with a vanilla Cordova install. However, when adding the 
cordova-plugin-wkwebview-engine, the Javascript callbacks do not fire correctly 
when receiving the VoIP silent push notification while the app is in the 
background. What happens is the first notification is queued, then the next 
notification forces the first notification result to the callback. Effectively, 
making each push notification 1 behind. When the app is put back into the 
foreground, the last push notification callback is fired.

When the app is in the foreground, all works fine.

The issue is with the call to "setTimeout" in the iOSExec.nativeCallback 
function. It makes sense that if Apple is trying to minimize background 
execution to save battery, then they would limit the use of the setTimeout 
feature. 

This issue is fixed by changing the iOSExec.nativeCallback function to call the 
cordova.callbackFromNative function directly without a setTimeout wrapper.

    iOSExec.nativeCallback = function(callbackId, status, message, 
keepCallback, debug) {
        var success = status === 0 || status === 1;
        var args = convertMessageToArgsNativeToJs(message);
    
     //   setTimeout(function(){
            cordova.callbackFromNative(callbackId, success, status, args, 
keepCallback);
     //   }, 0);
    };

  was:
iOS 10 now has power saving requirements and will not allow background tasks to 
function to save battery. For example, a VoIP app can no longer use a polling 
strategy to stay awake. The new recommended way, according to Apple 
(https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html),
 is to use VoIP silent push notifications to wake up the app and do the work. 

I have verified that all VoIP silent push notifications arrive correctly when 
using the UIWebView with a vanilla Cordova install. However, when adding the 
cordova-plugin-wkwebview-engine, the Javascript callbacks do not fire correctly 
when receiving the VoIP silent push notification while the app is in the 
background. What happens is the first notification is queued, then the next 
notification forces the first notification result to the callback. Effectively, 
making each push notification 1 behind. When the app is put back into the 
foreground, the last push notification callback is fired.

When the app is in the foreground, all works fine.

The issue is with the call to "setTimeout" in the iOSExec.nativeCallback 
function. It makes sense that if Apple is trying to minimize background 
execution to save battery, then they would limit the use of the setTimeout 
feature. 

This issue is fixed by changing the iOSExec.nativeCallback function to call the 
cordova.callbackFromNative function directly without a setTimeout wrapper.




> WKWebView plugin will not execute Javascript while app is backgrounded
> ----------------------------------------------------------------------
>
>                 Key: CB-12815
>                 URL: https://issues.apache.org/jira/browse/CB-12815
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-wkwebview-engine
>         Environment: iOS
>            Reporter: Rich Storm
>            Assignee: Shazron Abdullah
>              Labels: Background, Javascript, WKWebView
>
> iOS 10 now has power saving requirements and will not allow background tasks 
> to function to save battery. For example, a VoIP app can no longer use a 
> polling strategy to stay awake. The new recommended way, according to Apple 
> (https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html),
>  is to use VoIP silent push notifications to wake up the app and do the work. 
> I have verified that all VoIP silent push notifications arrive correctly when 
> using the UIWebView with a vanilla Cordova install. However, when adding the 
> cordova-plugin-wkwebview-engine, the Javascript callbacks do not fire 
> correctly when receiving the VoIP silent push notification while the app is 
> in the background. What happens is the first notification is queued, then the 
> next notification forces the first notification result to the callback. 
> Effectively, making each push notification 1 behind. When the app is put back 
> into the foreground, the last push notification callback is fired.
> When the app is in the foreground, all works fine.
> The issue is with the call to "setTimeout" in the iOSExec.nativeCallback 
> function. It makes sense that if Apple is trying to minimize background 
> execution to save battery, then they would limit the use of the setTimeout 
> feature. 
> This issue is fixed by changing the iOSExec.nativeCallback function to call 
> the cordova.callbackFromNative function directly without a setTimeout wrapper.
>     iOSExec.nativeCallback = function(callbackId, status, message, 
> keepCallback, debug) {
>         var success = status === 0 || status === 1;
>         var args = convertMessageToArgsNativeToJs(message);
>     
>      //   setTimeout(function(){
>           cordova.callbackFromNative(callbackId, success, status, args, 
> keepCallback);
>      //   }, 0);
>     };



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to