PhoneGap/Cordova 1.5 iOS“;“请勿备份”;文件属性

PhoneGap/Cordova 1.5 iOS“;“请勿备份”;文件属性,ios,cordova,icloud,phonegap-build,Ios,Cordova,Icloud,Phonegap Build,根据苹果网站上的开发者文档: 从iOS 5.0.1开始,引入了一个新的“不备份”文件属性,允许开发人员明确指定应该备份哪些文件。(com.apple.MobileBackup) 我想知道PhoneGap/Cordova是否支持这一点,因为我希望能够存储一些未在iCloud上备份的脱机数据(可以下载或以其他方式重新创建,但用户希望在脱机时可靠可用的数据) 持久性在PhoneGap网站上有明确的文档记录(LocalFileSystem.PERSISTENT-),但似乎无法确保保存的文件不备份到iCl

根据苹果网站上的开发者文档:

从iOS 5.0.1开始,引入了一个新的“不备份”文件属性,允许开发人员明确指定应该备份哪些文件。(com.apple.MobileBackup)

我想知道PhoneGap/Cordova是否支持这一点,因为我希望能够存储一些未在iCloud上备份的脱机数据(可以下载或以其他方式重新创建,但用户希望在脱机时可靠可用的数据)


持久性在PhoneGap网站上有明确的文档记录(LocalFileSystem.PERSISTENT-),但似乎无法确保保存的文件不备份到iCloud。

我仍在等待PhoneGap/Cordova中的解决方案,但作为临时解决方案

在my AppDelegate init中:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

// Get documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *formularyPath = [documentsDirectory stringByAppendingPathComponent:@"OfflineData"];

if (![[NSFileManager defaultManager] fileExistsAtPath:formularyPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:formularyPath withIntermediateDirectories:NO attributes:nil error:nil];

// Prevent iCloud backup
u_int8_t b = 1;
setxattr([formularyPath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
不要忘记导入“sys/xattr.h”

这将在“文档”下创建一个新文件夹,并设置“无备份”属性


然后,您可以使用“持久化本地文件存储”选项将文件保存在PhoneGap中,保存在新子目录中的文件将不会备份。

我仍在等待PhoneGap/Cordova中的解决方案,但作为临时解决方案

在my AppDelegate init中:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

// Get documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *formularyPath = [documentsDirectory stringByAppendingPathComponent:@"OfflineData"];

if (![[NSFileManager defaultManager] fileExistsAtPath:formularyPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:formularyPath withIntermediateDirectories:NO attributes:nil error:nil];

// Prevent iCloud backup
u_int8_t b = 1;
setxattr([formularyPath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
不要忘记导入“sys/xattr.h”

这将在“文档”下创建一个新文件夹,并设置“无备份”属性


然后,您可以使用持久化本地文件存储选项将文件保存在PhoneGap中,保存在新子目录中的文件将不会被备份。

下面是一个功能正常的JS代码示例,它利用Cordova框架,我相信它解决了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);

}

下面是一个功能强大的JS代码示例,它利用了Cordova框架,我相信它解决了苹果所寻找的问题

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);

}

由于Phonegap 1.9,您可以在config.xml中设置:

 <preference name="BackupWebStorage" value="none" />

BackupWebStorage(字符串,默认为cloud):有效值为none、cloud和local。设置为cloud以允许将web存储数据备份到iCloud,设置为local以仅允许本地备份(iTunes sync)。设置为“无”不允许对web存储进行任何备份

为了检查它是否有效,苹果建议通过以下方式检查您在iCloud的支持下输入了多少数据:

  • 安装并启动你的应用程序
  • 进入设置>iCloud>存储和备份>管理存储
  • 如有必要,点击“显示所有应用”
  • 检查应用程序的存储空间

请注意,这不能在模拟器中完成。您需要一台真正的设备。

由于Phonegap 1.9,您可以在config.xml中设置:

 <preference name="BackupWebStorage" value="none" />

BackupWebStorage(字符串,默认为cloud):有效值为none、cloud和local。设置为cloud以允许将web存储数据备份到iCloud,设置为local以仅允许本地备份(iTunes sync)。设置为“无”不允许对web存储进行任何备份

为了检查它是否有效,苹果建议通过以下方式检查您在iCloud的支持下输入了多少数据:

  • 安装并启动你的应用程序
  • 进入设置>iCloud>存储和备份>管理存储
  • 如有必要,点击“显示所有应用”
  • 检查应用程序的存储空间

请注意,这不能在模拟器中完成。你需要一台真正的设备。

谢谢你的回答@LeeCrossley!!我参与了一个PhoneGap项目,该项目下载的数据应该是持久的,不需要备份,但是,由于我们使用的版本是1.7,我们不能使用
setMetadata
功能,现在升级到1.8会非常混乱。只是一个问题,你有没有在app store上发布任何与此代码相关的内容?我看不出它被拒绝的原因,但是,由于我既没有objective-c的经验,也没有在应用商店发布的经验,我想确定一下,这个应用程序:itunes.apple.com/gb/app/nice-bnf/id523093958使用上述代码,目前运行1.7。谢谢@LeeCrossley!!我参与了一个PhoneGap项目,该项目下载的数据应该是持久的,不需要备份,但是,由于我们使用的版本是1.7,我们不能使用
setMetadata
功能,现在升级到1.8会非常混乱。只是一个问题,你有没有在app store上发布任何与此代码相关的内容?我看不出它被拒绝的原因,但是,因为我既没有objective-c的经验,也没有在应用商店发布的经验,我想确定一下,这个应用程序:itunes.apple.com/gb/app/nice-bnf/id523093958使用上述代码,目前运行1.7。这是近两年前的一个老问题,与1.5版有关,在功能实现之前。是的,你是对的,但问题仍然存在,我想帮助其他用户。这是近两年前的一个老问题,与功能实现之前的版本1.5有关。是的,你是对的,但问题仍然存在,我想帮助其他用户。