Tag: Cloud size standard named user call code about TPS
Local storage of data and picture caching can greatly improve the user experience of the app, improve UI responsiveness, and reduce network usage.
1.uzStorage
Uzstorage is more secure and easy to use than standard localstorage.
For a chestnut: localstorage There are limitations of size, async can cause some security, can not store objects and other problems, but these problems are resolved in uzstorage.
2. Preference Settings
3. Documents
Apicloud provides a standard file-handling interface that supports synchronous and asynchronous invocation methods. Use the following API to manipulate the file:
Api.readfile ({? sync:false,//is synchronous, default False?path: "PathToFile"//file path, supports absolute path and file path protocol such as fs://, widget://, etc.
}, function (Ret,err) {
ret = {status:true,data: ""}
}); Err = {code:0,msg: ""}
Api.writefile ({? Path: "PathToFile",//file path, supports absolute path and file path protocol such as fs://, cache://, etc., does not support widget://directory,
This directory is read only? data: "Data",//file contents
append:false//whether the data is written in Append mode, default False, clears the previous file contents}, function (Ret,err) {
ret = {Status:true}
}); Err = {code:0,msg: ""}
4.database
Using the "DB" module to operate the database, "DB" module encapsulates the mobile phone database SQLite additions and deletions of the statement, can realize the local storage of data, greatly simplifying the data persistence problem, and support synchronization interface.
5. Storage capacity
Apicloud provides an API for storage capacity with the following code:
Api.getfreediskspace ({? sync:false//) The return method of the execution result. False when returned by callback, true when returned directly, false by default
}, function (Ret,err) {?//ret = {size:1024} The amount of storage space remaining, in byte, and number type. (-1: No storage device,-2: Preparing USB memory
Storage device,-3: Unable to access the memory Device)});
Api.gettotalspace ({? Sync:false//The return method of the execution result. False when returned by callback, true when returned directly, false by default
}, function (Ret,err) {?//ret = {size:1024} total storage size, in bytes, numeric type. (-1: No storage device,-2: Preparing USB Storage
Device,-3: Unable to access the storage device)});
Api.getcachesize ({? sync:false//) The return method of the execution result. False when returned by callback, true when returned directly, false by default
}, function (Ret,err) {?//ret = {size} cache size, in bytes, numeric type. (-1: No storage device,-2: Preparing USB storage device,-3: None
Access to storage devices)
});
Api.clearcache ({timethreshold:10//(optional) clear how many days ago the cache, default 0
}, function (Ret,err) {}); Clear complete
6. Sandbox mechanism
The virtual sandbox mechanism is used in both Android and IOS to ensure the security and independence of data storage, and the APP can only access the sandbox area of its own file system. The sandbox location is as follows.
? Default sandbox location for Android: Sdcard/uzmap/appid.?
? Default sandbox location for IOS: Documents/uzfs/appid.?
7. Resource access agreement?
Apicloud resources are stored in the App installation package (IPA package or APK package) or in the application sandbox. Sandbox is divided into Apicloud application virtual sandbox and Native application real sandbox, the real sandbox is the operating system for the app on the device internal storage allocated space, not visible, only allow the app itself to access.
? 8. Picture Cache?
For picture caching, you can use the following code:
? ? var img = $api. Byid ("myimg");
? Api.imagecache ({
? ? URL: ' Http://example.com/dir/file.png '
? },function (Ret,err) {
? ? if (ret && ret.status = = True) {
? } img.src = Ret.url;
???? else{}//Handling errors?}); ?
The above code first specifies the remote picture path (URL) to be cached in the parameter, and in the subsequent callback function determines whether the cache succeeds (if (ret && ret.status = = True) {}), and if successful you can use Ret.url to update
Label. Ret.url is the path after the picture is cached to the local.
For more app information, please follow www.apicloud.com
Submit app customization requirements to learn about quotes and cycles:
https://app.apicloud.com/index?uzchannel=500
How does the app do local storage and picture caching?