question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With Cordova and the cordova-plugin-wkwebview-engine I can no longer play sounds without direct user action when the App is installed over the official Apple App-Store!

See original GitHub issue

Bug Report

If I use the cordova-plugin-wkwebview-engine and play a soundfile, i become follow assertion.

2020-07-10 13:40:04.054571+0200 TEST[1927:49192] [assertion] Error acquiring assertion: <NSError: 0x600002e7ba80; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
    userInfo = {
        RBSAssertionAttribute = <RBSLegacyAttribute: 0x7fce0fd216e0; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
    }
}

This is not nice but not the real problem.

If I install this app via the app store and the audio object of this sound file plays automatically without user action, for example after receiving an SIO message, the assertion causes the app to crash.

The really deadly problem is that with Cordova and the cordova-plugin-wkwebview-engine I can no longer play sounds without direct user action when the App is installed over the official Apple App-Store! The App will be closed after crash!

Note: The problem only occours if I use the cordova-plugin-wkwebview-engine, without everything is fine.

Steps to reproduce the Assertion in X-Code

Important NOTE: The assertion also occurs in the iPhone simulator.

  • Install the newest X-Code Version 11.5 (11E608c) on your Mac with macOS 10.15.5
  • Create a fresh and new Cordova App for iOS. You can use follow script:
#!use this two lines to install the lastest cordova version 
#!sudo npm uninstall -g cordova
#!sudo npm install -g cordova
rm -r PhoneGap_ios
cordova create PhoneGap_ios de.test.test Test
cd PhoneGap_ios
cordova platform add ios
cordova plugin add cordova-plugin-wkwebview-engine
cordova plugin ls
  • Open the X-Code Project and add follow line in the cordova index.html (project/Staging/www/index.html):
<input type="button" id="buttontest" value="Click me..."/>

The complete changed index.html look like this:

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
            <input type="button" id="buttontest" value="Click me..."/>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>
  • Open the X-Code Project and add follow line in the cordova index.js (project/Staging/www/js/index.js):
onDeviceReady: function() {
        this.receivedEvent('deviceready');
        
        document.getElementById('buttontest').addEventListener('click', function() {
            console.log('Received Event click: start #############################');
            try {
              var audio = new Audio('sounds/s1.wav');
              audio.play();
            }
            catch(err) {
              console.log(err.message);
            }

            console.log('Received Event click: end -----------------------------');
        });
    },

The complete changed index.js look like this:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
        
        document.getElementById('buttontest').addEventListener('click', function() {
            console.log('Received Event click: start #############################');
            try {
              var audio = new Audio('sounds/s1.wav');
              audio.play();
            }
            catch(err) {
              console.log(err.message);
            }

            console.log('Received Event click: end -----------------------------');
        });
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

When I start the app on the iPhone (in this sample it is an iPhone X), the new button is showing.

Bildschirmfoto 2020-07-10 um 14 12 49

After click the button follow message is showing in the X-Code

2020-07-10 14:16:40.964661+0200 TEST[2123:63730] Received Event click: start #############################
2020-07-10 14:16:40.983068+0200 TEST[2123:63730] Received Event click: end -----------------------------
2020-07-10 14:16:41.101598+0200 TEST[2123:63842] [assertion] Error acquiring assertion: <NSError: 0x6000029ec4b0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
    userInfo = {
        RBSAssertionAttribute = <RBSLegacyAttribute: 0x7fce0fd202c0; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
    }
}
2020-07-10 14:16:41.101697+0200 TEST[2123:63842] [ProcessSuspension]  0x116baab68 - ProcessAssertion() PID 2123 Unable to acquire assertion for process with PID 2123
2020-07-10 14:16:41.101786+0200 TEST[2123:63730] [ProcessSuspension] 0x116baab68 - ProcessAssertion::processAssertionWasInvalidated()
2020-07-10 14:16:41.103452+0200 TEST[2123:63842] [assertion] Error acquiring assertion: <NSError: 0x6000029dd0b0; domain: RBSAssertionErrorDomain; code: 2; reason: "Client is missing required entitlement"> {
    userInfo = {
        RBSAssertionAttribute = <RBSLegacyAttribute: 0x7fce11229040; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
    }
}
2020-07-10 14:16:41.103541+0200 TEST[2123:63842] [ProcessSuspension]  0x116baabb8 - ProcessAssertion() PID 2123 Unable to acquire assertion for process with PID 2129
2020-07-10 14:16:41.103617+0200 TEST[2123:63730] [ProcessSuspension] 0x116baabb8 - ProcessAssertion::processAssertionWasInvalidated()

What is expected to happen?

No error message appeares.

What does actually happen?

The error message appeares.

Command or Code

see above

Environment, Platform, Device

  • iMac17,1 with macOS 10.15.5
  • X-Code Version Version 11.5 (11E608c) with the related SDK
  • Latest Cordova Version (‘5.1.1’ in cordova.js)

Version information

see above

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
breautekcommented, Jul 10, 2020

Sounds like you need an entitlement now based on:

reason: “Client is missing required entitlement”>

But… there doesn’t seem to be any entitlements for media playback. And according to one user on this thread:

Unfortunately, from iOS 13 this ability is under sytem entitlements, com.apple.multitasking.systemappassertions and com.apple.multitasking.unlimitedassertions, you can try it in simulator, no error in log. There is no way to launch it on device thought, as you need an Apple issued provision profile. So, all we can do is to hope that some future release will fix this.

I don’t have a test device, so I can’t really play around with this, just posting some relevant information I found while searching for potential solutions and/or workarounds.

1reaction
RonnySchleichercommented, Sep 18, 2020

In my opinion it is not possible to play sounds in the old way. It is necessary to request a promise to allow a url to an audio file to be played.

See the follow link

https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/

I solved the problem for myself by using the cordova-plugin-media https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-media/

Read more comments on GitHub >

github_iconTop Results From Across the Web

If an app is not from the Mac App Store - Apple Support
Most apps can be found in the Applications folder. Control-click the app, then choose Open from the shortcut menu. Click Open. The app...
Read more >
App Store Connect - Support - Apple Developer
App Store Connect is a suite of web-based tools for managing apps sold on the App Store for iPhone, iPad, Mac, Apple Watch,...
Read more >
In-App Events - App Store - Apple Developer
In -app events are timely events within apps and games — such as game competitions, movie premieres, live-streamed experiences, and more.
Read more >
App Store Connect Help - Apple Support
If you don't change their app access, they can access all apps by default. Learn how to manage users with the App Store...
Read more >
Distribute proprietary in-house apps to Apple devices
If not, you can distribute just the new .mobileprovision file, so users won't have to install the app again. The new provisioning profile ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found