Download/Save a URL Image file to Photo Gallery for iOS

I have been trying to download a URL Image file to the photo gallery on iOS. but it ends with an permission error. have a look at my code that am using to store image.

$scope.Download = function (imgurl) {
var url = imgurl;
var filename = url.split("/").pop();
var targetPath = cordova.file.documentsDirectory + filename;
$, targetPath, {}, true).then(function (result) {
$scope.hasil = ‘Save file on ‘+targetPath+’ success!’;
}, function (error) {
$scope.hasil = ‘Error Download file’;
}, function (progress) {
$scope.downloadProgress = (progress.loaded / * 100;
if am wrong on any point. please let me know.
Thanks for the help.