【发布时间】:2014-05-01 12:59:54
【问题描述】:
我的应用程序被拒绝,因为它向 iCloud 备份了太多数据。
为了解决这个问题,我必须将我的所有文件放在一个新目录中,该目录位于 ApplicationSupportDirectory 中。 到目前为止我还没有做到这一点,我无法弄清楚似乎是什么问题。
这是我目前的代码:
AppDelegate.m 类:
- (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) 时出错;
我有什么遗漏吗? 首先,困扰我的是 - 是否有任何代码行我应该写甚至告诉我希望我的所有方面都在那个特定的文件夹中,我以后想跳过备份? 如果我应该这样做,我应该在哪里? AppDelegate.m 还是其他地方?
AppDevelopment 的这一部分是我以前从未接触过的,所以我真的迷失了。
【问题讨论】:
标签: ios app-store nsdocumentdirectory