IOS10 kills firebase websocket


#1

I am using Ionic v1 and Firebase v2.

Since IOS10, when I try to upload a base64 encoded image to my firebase using cordova camera, the websocket between my app and firebase gets killed for about 25 seconds, before it comes back to life.

This happens only on IOS10, android and all other ios versions work just fine.

After (a lot) of research online, I found that I have to add the following to my Info.plist, which I did :

 <key>NSCameraUsageDescription</key>
    <string/>
    <key>NSMicrophoneUsageDescription</key>
    <string/>
    <key>NSPhotoLibraryUsageDescription</key>
    <string/>

Then I also found out that the content security policy (CSP) meta tag needed some changes to take into account ios10. Here is my CSP tag :

<meta http-equiv="Content-Security-Policy"
        content="
        default-src 'self' gap://ready file://* https://graph.facebook.com wss://* *;
        script-src * 'self' 'unsafe-eval' 'unsafe-inline' https://graph.facebook.com cdn.firebase.com https://*.firebaseio.com;
        connect-src * 'self' 'unsafe-inline' 'unsafe-eval' https://graph.facebook.com *.firebaseapp.com https://*.firebaseio.com ws:// wss://*.firebaseio.com blob: data:;
        style-src * 'unsafe-inline'; 
        img-src * 'unsafe-eval' 'unsafe-inline' data:">

As you can see, there is everything I could ever need to reach firebase properly.

Again, all other request to firebase work fine, but only this specific base64 upload (about 100Kb) kills my websocket.

Just in case, here is the code I use with my cordova camera to upload my image :

$scope.takePicture = function() {
        var options = { 
            quality : 90, 
            destinationType : Camera.DestinationType.DATA_URL, 
            sourceType : Camera.PictureSourceType.CAMERA, 
            allowEdit : false,
            encodingType: Camera.EncodingType.JPEG,
            correctOrientation: true,
            targetWidth: 400,
            targetHeight: 400, 
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: false
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.imgURI = "data:image/jpeg;base64," + imageData;
            var myRef = new Firebase('https://myawesomeapp.firebaseio.com/linktomynode); 
            myRef.update({"photo":$scope.imgURI});
        }, function(err) {
            console.log(err);
        });
      }

I also started to believe that it was because of memory leaking using the cordova camera, when the image I get is too big ? If it’s less than 20Kb it gets uploaded to firebase right away. (if I take a picture of the wall, the image gets smaller) But if it’s more, that’s where the websocket gets killed.

Please anyone, I’m going bald with this issue.