Phonegap-iOS在iCloud上防止文档文件夹备份

时间:2014-05-05 12:49:32

标签: ios cordova

我的应用程序由于不正确使用iCloud备份而被拒绝。

很快,我有一个预先填充的数据库存储在Documents文件夹中,我需要将其从iCloud备份中排除。

我的问题是:

1)config.xml中的BackupWebStorage设置是否设置为“none”?或者它只是阻止备份WebKit文件夹?

2)如果它不起作用,我知道我应该使用以下代码:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

但是(脸红),我不知道我应该如何在这段代码中指定文件,让我们说路径是:

文档/ 0000000000000001.db

我要在哪里表明?

真的,感谢各种帮助。

提前致谢

啤酒

3 个答案:

答案 0 :(得分:1)

我认为该设置仅适用于网络存储(虽然目前尚不清楚)。

在过去,我已经完全确定使用去年写的这个要点,没有任何内容备份到文档或库目录中的iCloud:

https://gist.github.com/leecrossley/4130115

答案 1 :(得分:1)

你是否尝试过我在phonegap的谷歌小组中告诉你的内容?

您可以在.db文件中使用setMetadata函数,类似这样

// Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }

    function gotFS(fileSystem) {
        fileSystem.root.getFile("0000000000000001.db", null, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {

        // Set the metadata
        fileEntry.setMetadata(success, fail, { "com.apple.MobileBackup": 1});

    }

    function success() {
        console.log("The metadata was successfully set.");
    }

    function fail() {
        alert("There was an error in setting the metadata");
    }

答案 2 :(得分:0)

我尝试添加以下代码:

NSString* doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* lib = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];

float version = [[[UIDevice currentDevice] systemVersion] floatValue];

if (version < 5.1)
{
    NSLog(@"************ iOS 5.0");
    u_int8_t b = 1;
    setxattr([doc fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
    setxattr([lib fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}
else
{
    NSLog(@"************ iOS 5.1");
    NSURL* url = [NSURL fileURLWithPath:doc];
    [url setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: Nil];
    url = [NSURL fileURLWithPath:lib];
    [url setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: Nil];
}


NSLog(@"************ FILES FLAGGED");

之后
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
AppDelegate.m中的

它运行顺利但是,当我使用终端测试结果时:

  • 在新的终端窗口中打开Simulator App的Documents文件夹

  • 检查文件属性(我的数据库路径是Documents / 0000000000000001.db):

    xattr -l 0000000000000001.db
    

我得不到任何回复,(至少我认为)意味着文件没有被标记。

有没有我错过的东西?

感谢您的耐心

的Alessandro

相关问题