Issue:
White screen on iOS Cordova app when returning from background after memory pressure (App becomes frozen and unresponsive).
DESCRIPTION:
I’m encountering a white screen issue on iOS when using a Meteor + Cordova mobile app. Specifically, if the Cordova app is backgrounded and another memory-intensive app is launched, returning to the Cordova app results in a frozen white screen. There’s no recovery mechanism, and the user is forced to kill and restart the app.
STEPS TO REPRODUCE:
- Launch the Cordova app on an iOS device.
- Background the app.
- Open a memory-intensive app (e.g., Camera, Photos).
- Wait or interact with the memory-heavy app.
- Return to the Cordova app.
- Observe: the app shows a white screen and is completely unresponsive.
CURRENT BEHAVIOR:
- White screen shown upon returning
- App frozen with no navigation or reload
- Must kill and relaunch the app manually
EXPECTED BEHAVIOR:
- App should reload automatically
- No white screen or freeze
- App remains usable after memory pressure event
ROOT CAUSE:
iOS can kill backgrounded apps during memory pressure. When this happens, the Cordova WebView doesn’t properly reload upon restoration, leading to the white screen.
FIX IMPLEMENTED:
I applied the fix from apache/cordova-ios#1552, which modifies CDVWebViewEngine.m
to also check for the title as “” along with the null and try to reload the app URL with cache-busting logic. This works as expected and prevents the white screen issue.
Our fix is a hack becuase our app always has a title. If there are pages without titles it could be a less than ideal fix:
BOOL title_is_nil = (title == nil) || [title isEqualToString:@""];
Modified CDVWebViewEngine.m
: Updated the onAppWillEnterForeground:
method to reload the app URL with cache disabled instead of just calling reload()
:
// PATCH FOR WHITE SCREEN OF DEATH:
// Instead of just calling reload, we need to reload the app URL with cache disabled
NSURL* url = [((CDVViewController*) self.viewController) appUrl];
NSURLRequest* appReq = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
[((WKWebView*)_engineWebView) loadRequest:appReq];
I placed the modified files inside cordova-build-override/platforms/ios/CordovaLib
as per Meteor’s override mechanism, and verified that it works across multiple iOS devices and memory conditions.
QUESTION:
Meteor 3.3 currently uses cordova-ios version 7.1.1, and that’s the version I patched. I’d like to create a PR upstream to the Apache Cordova project with this fix.
My main question is:
What’s the right way to proceed?
Should I create a PR targeting the Cordovamaster
branch or patch the7.1.1
tag/branch (if that’s what Meteor will use for some time)? Will future Meteor versions eventually use Cordova master or later Cordova iOS releases?
Any guidance from the Meteor team on how Cordova updates are managed in Meteor, and whether I should coordinate the fix through Meteor or directly with the Cordova maintainers, would be very helpful.