cordova version : 2.3
last update : 24/04/2013
PhoneGap plugin for managing application assets with javascript asset maps. Includes( iOS background threaded) downloadFile, getFileURI, getFileURIs, deleteFile.
- Updated for Cordova 2.3
- Changed deleteFile error handling.
- Removed unimplemented plugin methods.
- Updated error handling to more closely follow the w3c file api error conventions http://www.w3.org/TR/FileAPI/
- Added Android version.
Project tree
project
/ www
-index.html
/ assets [store your app assets here]
/ phonegap
/ plugin
/ wizAssets
/ wizAssets.js
/ Classes
/ Plugins
/ WizAssetsPlugin
/ WizAssetsPlugin.h
/ WizAssetsPlugin.m
-project.xcodeproj
1 ) Arrange files to structure seen above.
2 ) Add to cordova.plist in the plugins array;
Key : WizAssetsPlugin
Type : String
Value : WizAssetsPlugin
3 ) Add <script> tag to your index.html
<script type="text/javascript" charset="utf-8" src="phonegap/plugin/wizAssets/wizAssets.js"></script>
^ assuming your index.html is setup like tree above
4 ) Follow example code below...
Project tree
project
/ assets
/ www
-cordova-2.3.0.js
-index.html
/ assets [store your app assets here]
/ phonegap
/ plugin
/ wizAssets
-wizAssets.js
-assets.db [list your bundled assets here]
/ src
/ jp.wizcorp.phonegap.plugin.WizAssets
-WizAssetManager.java
-WizAssetsPlugin.java
1 ) Arrange source files to structure seen above.
2 ) Add to res/xml/config.xml the following line;
<plugin name="WizAssetsPlugin" value="jp.wizcorp.phonegap.plugin.WizAssets.WizAssetsPlugin"/>
3 ) Add <script> tag to your index.html
<script type="text/javascript" charset="utf-8" src="phonegap/plugin/wizAssets/wizAssets.js"></script>
(assuming your index.html is setup like tree above)
4 ) Follow example code below...
wizAssets.downloadFile(String URL, String filePathToBeStoredWithFilename, Function success, Function fail);
- downloads a file to native App directory @ ./ + gameDir+ / +filePathToBeStoredWithFilename
- A success returns URI string like; file://documents/settings/img/cards/card001.jpg
- example;
wizAssets.downloadFile("http://google.com/logo.jpg", "img/ui/logo.jpg", successCallback, failCallback);
wizAssets.deleteFile(string URI, Function success, Function fail);
- deletes the file specified by the URI
- if the URI does not exist fail will be called with error NotFoundError
- if the URI cannot be deleted (i.e. file resides in read-only memory) fail will be called with error NotModificationAllowedError
wizAssets.deleteFile("file://documents/settings/img/cards/card001.jpg", successCallback, failCallback);
wizAssets.deleteFiles(Array manyURIs, Function success, Function fail );
- delete all URIs in Array like; [ "file://documents/settings/img/cards/card001.jpg", "file://documents/settings/img/cards/card002.jpg " .. ]
- if you do not specify a filename only dir, then all contents of dir will be deleted; file://documents/settings/img/cards
- the array CAN contain one URI string
wizAssets.getFileURI(String filePathWithFilename, Function success, Function fail);
- A success returns URI string like file://documents/settings/img/cards/card001.jpg
- example;
wizAssets.getFileURI("img/ui/logo.jpg", successCallback, failCallback);
wizAssets.getFileURIs(Function success, Function fail);
- A success returns URI hashmap such as
{
"img/ui/loader.gif" : "/sdcard/<appname>/img/ui/loading.gif",
"img/cards/card001.jpg" : "file://documents/settings/img/cards/card001.jpg"
}