Skip to content

Commit

Permalink
feat(): read cached images as base64 encoded strings for iOS/WkWebView (
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Shaaban authored and ihadeed committed Jan 16, 2017
1 parent f77b6cf commit 4b612a2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { File, FileEntry, Transfer } from 'ionic-native';
import { File, FileEntry, FileReader, Transfer } from 'ionic-native';
import { ImageLoaderConfig } from "./image-loader-config";

declare var cordova: any;
Expand Down Expand Up @@ -268,7 +268,27 @@ export class ImageLoader {
File.resolveLocalFilesystemUrl(dirPath + '/' + fileName)
.then((fileEntry: FileEntry) => {
// file exists in cache
resolve(fileEntry.nativeURL);

// now check if iOS device & using WKWebView Engine
if (cordova.device.platform === 'iOS' && (<any>window).webkit) {

// Read FileEntry and return as data url
fileEntry.file((file: Blob) => {
const reader = new FileReader();

reader.onloadend = function() {
resolve(this.result);
};

reader.readAsDataURL(file);
}, reject);

} else {

// return native path
resolve(fileEntry.nativeURL);

}
})
.catch(reject); // file doesn't exist

Expand Down

0 comments on commit 4b612a2

Please sign in to comment.