我的应用由于以下问题被拒绝:
我的应用是一个使用 SQL 数据库的词典,具备书签等功能...
因此,我在 appDelegate.m 中从苹果文档中复制了以下代码:
- (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;
}
但是用法如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self addSkipBackupAttributeToItemAtURL:[NSURL URLWithString:@"<myApplication>/Library/Caches"]];
}
但是出现了以下原因而崩溃:
断言失败:([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]), 函数 -[AppDelegate addSkipBackupAttributeToItemAtURL:], 文件 /iData/Development 2011/My iPhone Project/APPNAME/APPNAME/AppDelegate.m, 第27行。
根据图片显示,这是我被拒绝的唯一问题吗?因为这是我第一次使用数据库。
谢谢。
编辑:
- (NSString *) getDBPath
{
NSInteger kValue = [[[NSUserDefaults standardUserDefaults] stringForKey:@"Bv"] intValue];
NSString *documentsDir = [[NSString alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
documentsDir = [paths objectAtIndex:0];
switch (kValue) {
case 0:
documentsDir = [NSString stringWithFormat:@"%@/eng-per.sqlite", documentsDir];
break;
case 1:
documentsDir = [NSString stringWithFormat:@"%@/eng-per.sqlite", documentsDir];
break;
case 2:
documentsDir = [NSString stringWithFormat:@"%@/per-eng.sqlite", documentsDir];
break;
}
return documentsDir
然后在app delegate.m中更改为:
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:dbClass.getDBPath]];
现在应用程序可以正常启动而不会崩溃
NSURL fileURLWithPath:
而不是NSURL URLWithString:
来从文件路径创建NSURL
。 - rmaddyNSSearchPathForDirectoriesInDomains
返回的是路径字符串数组,而不是NSURL
对象。 - rmaddy