Home

Awesome

phonegap-plugin-wizAssets

Description

PhoneGap plugin for managing application assets with javascript asset maps. Includes downloadFile, getFileURI, getFileURIs, deleteFile, deleteFiles.

Install (with Plugman)

cordova plugin add https://github.com/Wizcorp/phonegap-plugin-wizAssets
cordova build ios

< or >

phonegap local plugin add https://github.com/Wizcorp/phonegap-plugin-wizAssets
phonegap build ios

APIs

wizAssets.initialize(success, fail)

Example

wizAssets.initialize(function () {
        console.log('wiz assets is ready to be used');
    }, function () {
        console.log('wiz assets did not initialize, it cannot be used');
    }
);

wizAssets.downloadFile(remoteURL, assetId, success, fail)

{
    "code": WizAssetsError value,
    "status": if code is a HTTP_REQUEST_ERROR, the status of the HTPP request, optional
    "message": description of the error if any
}

Example

wizAssets.downloadFile("http://google.com/logo.jpg", "img/ui/logo.jpg", successCallback, failCallback);

wizAssets.deleteFile(assetId, success, fail)

Example

wizAssets.deleteFile("img/cards/card001.jpg", successCallback, failCallback);

wizAssets.deleteFiles(assetIds, success, fail)

Example

wizAssets.deleteFiles(["img/cards/card001.jpg", "img/cards/card002.jpg"], successCallback, failCallback);

wizAssets.getFileURI(assetId, success, fail)

Example

wizAssets.getFileURI("img/ui/logo.jpg", successCallback, failCallback);

wizAssets.getFileURIs(success, fail)

{

    "img/ui/loader.gif"  : "/sdcard/<appname>/img/ui/loading.gif", 
    "img/cards/card001.jpg" : "file://documents/settings/img/cards/card001.jpg" 

}

Example

wizAssets.getFileURIs(successCallback, failCallback);

Error handling

All error codes are available via window.WizAssetsError.

Example

function fail(error) {
    if (error.code === window.WizAssetsError.HTTP_REQUEST_ERROR) {
        // Check error.status
    } else {
        // Log error code with error.message
    }
}
CodeConstantDescription
1ARGS_MISSING_ERRORArguments are missing in your call to WizAssets' method
2INVALID_URL_ERRORSpecified URL to download is invald
3CONNECTIVITY_ERRORDownload could not be processed because network could not be accessed
4HTTP_REQUEST_ERRORHTTP status of the request is not successful (not 2XX)
5HTTP_REQUEST_CONTENT_ERRORContent received in HTTP request could not be read
6DIRECTORY_CREATION_ERRORCreation of the directory to save the asset failed
7FILE_CREATION_ERRORSaving the asset failed
8JSON_CREATION_ERRORYour call to WizAssets' method failed and its error could not be processed internally
9INITIALIZATION_ERRORWizAssets initialization failed
10NOT_FOUND_ERRORAsset could not be found
11UNREFERENCED_ERRORUnknown error: message string (error.message) will contain more information