大佬教程收集整理的这篇文章主要介绍了iphone – 如何使用addSkipBackupAttributeToItemAtURL API?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我从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的文件夹,您可以通过以下方式执行此操作:
[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask];
(通过文件URL传回的位置)
要么
NSSearchPathForDirectoriesInDomains(NSCachesDirectory,YES);
(对于NSString形式的路径)
所以最终,如果密钥已经设置为默认值并且您需要正确设置要保存的文件的文件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"]; }
以上是大佬教程为你收集整理的iphone – 如何使用addSkipBackupAttributeToItemAtURL API?全部内容,希望文章能够帮你解决iphone – 如何使用addSkipBackupAttributeToItemAtURL API?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。