iOS app WKWebView error when uploading image

Viewed 2172

In a WKWebView I am receiving this warning when I upload the image to our server using FormData via Ajax. The entire process completes successfully.

Can anyone suggest what is the missing entitlement. I have reviewed entitlements related to WKWebView

In the console I see that the pid is associated with "webkit.uploads"

"Required client entitlement is missing" requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>

// xcode debug console on submit   
MyDomain[3002:428982] [ProcessSuspension]  0x104be68a0 - ProcessAssertion() PID 3002 Unable to acquire assertion for process with PID 3002
MyDomain[3002:427999] [ProcessSuspension] 0x104be68a0 - ProcessAssertion::processAssertionWasInvalidated()
MyDomain[3002:428982] [assertion] Error acquiring assertion: <NSError: 0x281b3b6f0; domain: RBSAssertionErrorDomain; code: 2; reason: "Required client entitlement is missing"> {
    userInfo = {
        RBSAssertionAttribute = <RBSLegacyAttribute: 0x100f2ee40; requestedReason: FinishTaskUnbounded; reason: FinishTaskUnbounded; flags: PreventTaskSuspend>;
    }
}


// javascript upload code
var formData=new FormData();
formData.append("action", 'save');

var fileInput = document.getElementById('addImage');
if (fileInput.files && fileInput.files[0]) {
    var file = fileInput.files[0
    formData.append('messageImage', file);
    hasFile = true;
}

if(hasFile){
    $.ajax({
       type: "POST",
       url: "/images/save",
       data: formData,
       dataType: 'json',
       contentType: false,
       processData: false,
       success: function(result){}
    });
}
2 Answers

I had a hunch about this and other errors coming from wkWebView, and I think I proved it. It has to do with the file uploads taking too long, and iOS complains about it, and wkWebView gets "released" (according to another thread). In my case, my uploads were taking between 5 and 13 seconds.

I implemented my upload in a Web Worker, which turned out to be a little tricky on Cordova, but all of the issues went away once I did this.

So my fix only seemed to address this in the emulator on my dev machine, which is using iOS 13.3. When I build on my "production" machine running iOS 13.7 the error returns. It was happening on both environments before moving file upload to a Worker.

It would seem Apple is in the process of adding something to iOS that is triggering these but has not yet documented or explained it. That's my new theory.

Related