Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B42EA200C67 for ; Mon, 15 May 2017 15:51:09 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B2D32160BC2; Mon, 15 May 2017 13:51:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D2697160BC1 for ; Mon, 15 May 2017 15:51:08 +0200 (CEST) Received: (qmail 64617 invoked by uid 500); 15 May 2017 13:51:08 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 64604 invoked by uid 99); 15 May 2017 13:51:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 May 2017 13:51:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 96D70C030F for ; Mon, 15 May 2017 13:51:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id OBoVX71qn5sl for ; Mon, 15 May 2017 13:51:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 37A7F5FDCF for ; Mon, 15 May 2017 13:51:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6D28EE0BCD for ; Mon, 15 May 2017 13:51:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 26BDA242F5 for ; Mon, 15 May 2017 13:51:04 +0000 (UTC) Date: Mon, 15 May 2017 13:51:04 +0000 (UTC) From: "Rich Storm (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (CB-12815) WKWebView plugin will not execute Javascript while app is backgrounded MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 15 May 2017 13:51:09 -0000 [ 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. {code:javascript} 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); }; {code} 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. {quote} 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); }; {quote} > 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. > {code:javascript} > 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); > }; > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org