不包括备份ApplicationSupportDirectory错误 [英] Error excluding ApplicationSupportDirectory from Backup

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

问题描述

我的应用得到了拒绝,因为它backsUp太多的数据到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.

这是我的code迄今:

This is my code so far:

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]从备份(空)错误排除(空);

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

有什么我思念?
首先,什么是窃听我是 - 有我应该写,甚至告诉我希望我在这特定的文件夹中所有方code中的任何行,那我以后要跳过备份?
如果我应该这样做,我应该在哪里?
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天全站免登陆