这是一个利用 Cordova 框架的功能性 JS 代码示例,我相信它可以解决 Apple 正在寻找的问题。
document.addEventListener("deviceready",onDeviceReady,false);
function onSetMetadataSuccess() {
console.log("success setting metadata - DONE DONE DONE!")
}
function onSetMetadataFail() {
console.log("error setting metadata")
}
function onGetDirectorySuccess(parent) {
console.log("success getting dir");
parent.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1});
}
function onGetDirecotryFail() {
console.log("error getting dir")
}
function onFileSystemSuccess(fileSystem) {
console.log("onFileSystemSuccess()")
var dirEntry = fileSystem.root;
dirEntry.getDirectory('Backups', {create: true, exclusive: false},
onGetDirectorySuccess, onGetDirecotryFail);
}
function onFileSystemFail(evt) {
console.log("!!!!! onFileSystem fail...")
console.log(evt.target.error.code);
}
/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// this and subsequent callbacks tells iOS not to store our data in iCloud.
// without it they rejected our app because of the way PG 1.8 does local->tem storage
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
}