iphone – 如何使用addSkipBackupAttributeToItemAtURL API?

iphone – 如何使用addSkipBackupAttributeToItemAtURL API?,第1张

概述我的申请因此问题被驳回: http://i.imgur.com/yajQh.png 我的应用程序是一个使用SQL DB,书签等的字典… 所以我从appDelegate.m中的Apple文档复制了这段代码: - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL{ assert([[NSFileManager defaultManage 我的申请因此问题被驳回:

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"]];}

但因为这个原因而崩溃:

Assertion Failed: ([[NSfileManager defaultManager] fileExistsAtPath:
[URL path]]),function -[AppDelegate
addSkipBackupAttributetoItemAtURL:],file /IData/Development 2011/My
iPhone Project/APPname/APPname/AppDelegate.m,line 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中更改为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,那么您需要做的就是断言.

使用以下内容创建您的URL(准确地说是文件URL):

NSArray * arrayOfURLs = [[NSfileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask];// make certain there's at least one file url returned by the above callif([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?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1066859.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存