2

I used telerik app builder platform to create application. I created download image functionality. This functionality is working on android device, but not on iOS. I don't know why it is not working.

When the user downloads an image using application in android device, then cordova filesystem creates directory and saves image into that directory and image was also shown in gallery. While user performs same action in iOS then it does not create any directory and the image is not shown in gallery. I haven't found where to save this image.

Please give suggestion on how to save downloaded image in iOS gallery.

My code is below

function onDeviceReady() {
var that = this,
App = new downloadApp(),
fileName = "sample.png",
uri = encodeURI("http://www.telerik.com/sfimages/default-source/logos/app_builder.png"),
folderName = "test";

navigator.splashscreen.hide();
App.run(uri, fileName, folderName);
}

downloadApp.prototype = {
run: function (uri, fileName, folderName) {
var that = this,
    filePath = "";

document.getElementById("download").addEventListener("click", function () {
    that.getFilesystem(
        function (fileSystem) {
            console.log(fileSystem);
            that.getFolder(fileSystem, folderName, function (folder) {
                filePath = folder.toURL() + "\/" + fileName;
                console.log(filePath);

                that.transferFile(uri, filePath)
            }, function () {
                console.log("failed to get folder");
            });

        },
        function () {
            console.log("failed to get filesystem");
        }
        );
});


},

getFilesystem: function (success, fail) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, fail);
},
getFolder: function (fileSystem, folderName, success, fail) {
fileSystem.root.getDirectory(folderName, { create: true, exclusive: false },     success, fail)
   },

transferFile: function (uri, filePath) {
var transfer = new FileTransfer();
transfer.download(
    uri,
    filePath,
    function (entry) {
        var targetPath = entry.toURL();
    },
    function (error) {
       console.log(error)
    }
    );
},
Fabio Berger
  • 1,921
  • 2
  • 24
  • 29
kapil darji
  • 101
  • 2
  • 16
  • Check this out http://stackoverflow.com/questions/21577230/phonegap-save-image-from-url-into-device-photo-gallery?rq=1 – aman.sood Mar 03 '16 at 09:54
  • Thank you for your suggestion , I have checked out above solutions but image is not download iPhone gallery and also i have not found actual location where to save that image in iPhone. – kapil darji Mar 03 '16 at 11:59
  • I am more of a native iOS developer so regarding location iOS doesn't provides access to file system directly. First can you check if you get a pop up for asking for permission to access photo library. Also please check if in your setting of app you have the access to photos. Meanwhile I will check on cordova documentation – aman.sood Mar 03 '16 at 13:19
  • try this if it helps https://www.npmjs.com/package/cordova-ios-photo-library – aman.sood Mar 04 '16 at 06:39

1 Answers1

0

Try to download by using https://www.npmjs.com/package/com-cordova-image-save-to-gallery plugin. It will download a picture from a given URL and save it to IOS Photo Gallery.

Cordova plugin add https://github.com/valwinjose007/cordova-image-save-to-gallery.git

How to use:

declare var CordovaImageSaveToGallery: any;

CordovaImageSaveToGallery.downloadFromUrl('https://picsum.photos/200/300',(res)=>{
    //download success
},(err)=>{
    //error on download
});
Alwin Jose
  • 696
  • 1
  • 5
  • 13