即使实现addSkipBackupAttributeToItemAtURL,仍然可以备份到iCloud? [英] Still backups to iCloud even when addSkipBackupAttributeToItemAtURL is implemented?

查看:320
本文介绍了即使实现addSkipBackupAttributeToItemAtURL,仍然可以备份到iCloud?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近的iOS应用程序刚被拒绝,因为应用程序正在将数据存储在Documents上,因此它由iCloud备份,因为数据是从服务器下载的,所以不允许这样做。

My recent iOS app just got rejected because the application is storing data on Documents so it is backed up by iCloud, this is not allowed since the data is downloaded from a server.

我正在尝试重建代码,并且在将数据存储在文件夹中时会遇到困难,而不是代替应用程序支持。

I'm trying to rebuild the code right now and have hit a tough spot when storing the data in the a folder calles Application Support instead.

但即便如此虽然我正在使用addSkipBackupAttributeToItemAtURL但它仍然显示为iCloud的备份。

But even though I'm using addSkipBackupAttributeToItemAtURL it still shows up as a backup to iCloud.

我只针对5.1,因此它不是版本问题。

I'm only targeting 5.1 so it's not a versioning problem.

我在下面添加了受影响的代码:

I've added the affected code here below:

    NSString *newPath = [NSMutableString stringWithFormat:@"%@/Library/Application Support/", NSHomeDirectory()];

    if (![[NSFileManager defaultManager] fileExistsAtPath:newPath]) //Does directory already exist?
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:newPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *guidesPath = [newPath stringByAppendingPathComponent:@"/Guides"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:guidesPath])  //Does directory already exist?
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:guidesPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *dataPath = [guidesPath stringByAppendingPathComponent:dbName];

    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *newGuidesPath = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *guidesURL = [NSURL URLWithString:newGuidesPath];
    [self addSkipBackupAttributeToItemAtURL:guidesURL];

    NSString* path = [dataPath stringByAppendingPathComponent: 
                      [NSString stringWithString: finalName] ];
    if (![fileManager fileExistsAtPath:path]) {
        [myData writeToFile:path atomically:YES];
        NSString *docFile = [dataPath stringByAppendingPathComponent: @"guideid.txt"];
        [[guideID dataUsingEncoding:NSUTF8StringEncoding] writeToFile:docFile atomically:NO];
        DLog(@"Saved database here:%@", path);
    }else{
        DLog(@"Already exists, no need to copy");
    }

}







 - (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;
}


推荐答案

实际上找到了一个解决方案,
我编码了不需要的URL。
刚刚将其添加到文件夹

Actually found a solution, I've encoded the URL which was not needed. Just added this to the folder

    NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath];
    [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL];

并跳过了排除方法,只是在代码中标记了它,这似乎有效。

And skipped the exclude method, just flagged it inside the code, which seems to work.

这篇关于即使实现addSkipBackupAttributeToItemAtURL,仍然可以备份到iCloud?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆