从备份中排除 ApplicationSupportDirectory 时出错 [英] Error excluding ApplicationSupportDirectory from Backup

查看:20
本文介绍了从备份中排除 ApplicationSupportDirectory 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序被拒绝,因为它向 iCloud 备份了太多数据.

MY App got rejected because it backsUp too much data to iCloud.

为了解决这个问题,我必须将我的所有文件放在一个新目录中,该目录位于 ApplicationSupportDirectory.到目前为止,我还没有设法做到这一点,我无法弄清楚似乎是什么问题.

In order to solve the problem, I have to put all of my files in a new directory, located in ApplicationSupportDirectory. I am not managing to do it so far and I cannot figure out what seems to be the problem.

这是我目前的代码:

AppDelegate.m 类:

AppDelegate.m class:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{

NSString* string = [[self applicationDocumentsDirectory] absoluteString];

if (![[NSFileManager defaultManager] fileExistsAtPath:string  isDirectory:NULL]) {
    NSError *error = nil;
    [[NSFileManager defaultManager] createDirectoryAtPath:string 
withIntermediateDirectories:YES attributes:nil error:&error];
    if (error){
        NSLog(@"I'm not even making your stupid dir");
    }
}
[self addSkipBackupAttributeToItemAtURL:[self applicationDocumentsDirectory]];
return YES;
}

- (NSURL *)applicationDocumentsDirectory
{

NSString *appSupportDir =   
[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask,  
YES) lastObject];
appSupportDir = [appSupportDir stringByAppendingPathComponent:@"MyAppDirectory"];
NSLog(appSupportDir);
return [NSURL URLWithString:appSupportDir];}


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

但最后,我得到了一个错误:[1535:60b] 从备份 (null) 中排除 (null) 时出错;

But at the end, I just get an error: [1535:60b] Error excluding (null) from backup (null);

有什么我遗漏的吗?首先,困扰我的是什么 - 是否有任何代码行我应该编写甚至告诉我希望我的所有部分都在该特定文件夹中,以后我想跳过备份?如果我应该这样做,我应该在哪里?AppDelegate.m 或其他地方?

Is there anything Im missing? For a start, what's bugging me is - is there any line of code I should write to even tell that I want all my side in that specific folder, that I later want to skip backing up? if I should do that, where should I? AppDelegate.m or somewhere else?

AppDevelopment 的这一部分是我以前从未遇到过的,所以我真的迷失在这里.

This part of AppDevelopment is something I never came across before, so I'm really lost in here.

推荐答案

您似乎没有在任何地方创建目录.在调用 addSkipBackupAttributeToItemAtURL 之前添加验证目录是否存在并在需要时创建它.

It seems like you don't create your directory anywhere. Before calling addSkipBackupAttributeToItemAtURL add a verification if the directory is there and create it if needed.

    if (![[NSFileManager defaultManager] fileExistsAtPath:[self applicationDocumentsDirectory] isDirectory:NULL]) {
            NSError *error = nil;        
            [[NSFileManager defaultManager] createDirectoryAtPath:[self applicationDocumentsDirectory] withIntermediateDirectories:YES attributes:nil error:&error];
            if (error){
                 //Something went wrong
            }
    }

这篇关于从备份中排除 ApplicationSupportDirectory 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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