iphone – 如何使用addSkipBackupAttributeToItemAtURL API?
我的申请因此问题被驳回:
http://i.imgur.com/yajQh.png 我的应用程序是一个使用SQL DB,书签等的字典… 所以我从appDelegate.m中的Apple文档复制了这段代码: - (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"]]; } 但因为这个原因而崩溃:
根据那张照片,这是我拒绝的唯一问题吗?因为这是我第一次使用数据库. 谢谢 . 编辑: - (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中更改为this: [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:dbClass.getDBPath]]; 现在app午餐很好没有崩溃 解决方法
你的应用程序正在“崩溃”,因为你正在点击该断言:
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); 我怀疑你的问题实际上是你如何设置URL: [NSURL URLWithString:@"<myApplication>/Library/Caches"]; 你如何获得“< myApplication>”的路径? 您需要获取应用程序的真正Cache的文件夹,您可以通过以下方式执行此操作:
要么
所以最终,如果密钥已经设置为默认值并且您需要正确设置要保存的文件的文件URL,那么您需要做的就是断言. 使用以下内容创建您的URL(准确地说是文件URL): NSArray * arrayOfURLs = [[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask]; // make certain there's at least one file url returned by the above call if([arrayOfURLs count] > 0) { // and this would just be the URL to the cache directory... NSURL * cacheDirectoryPath = [arrayOfURLs objectAtIndex: 0]; // ... to create a file url to your actual dictionary,you'd need to add a // filename or path component. // Assuming you save this as a property within your object self.cacheFileURL = [cacheDirectoryPath URLByAppendingPathComponent: @"myDatabase.db"]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |