MessageChannel onmessage doesn't respond as app is backgrounded in iOS 14

MessageChannel does not respond (via onmessage) if a message is posted to it just as your app is leaving the foreground on iOS 14. In iOS 13, it used to respond in this case.
Context: We have an app with a WKWebView that uses the q library above, and observed that the library no longer no longer resolved promises after switching from our app to another app.

What’s going on:
This 3rd party promise library works by posting a message on port 1, and listening to that message on port 2. This works fine until a message is posted just as you switch from our app to another app. When this happens, onmessage does not respond (and then messes up state in the 3rd party library).

More specifically, in JavaScript:
  • var channel = new MessageChannel();

  • channel.port2 posts a message

  • and channel.port1.onmessage responds (except for when the app is leaving the foreground)

On iOS 13 onmessage actually responds as the app is leaving the foreground.
Answered by msmtamburro in 643932022
I received a response from Apple: "Promptly suspending when entering the background is correct behavior according to the norm of iOS."

So just be aware that your message will be lost if you post it as your app enters the background.
Accepted Answer
I received a response from Apple: "Promptly suspending when entering the background is correct behavior according to the norm of iOS."

So just be aware that your message will be lost if you post it as your app enters the background.
MessageChannel onmessage doesn't respond as app is backgrounded in iOS 14
 
 
Q