gpt4 book ai didi

ios - App不在文档目录下存储任何内容但Appstore拒绝

转载 作者:可可西里 更新时间:2023-11-01 04:46:45 25 4
gpt4 key购买 nike

我是 iOS 开发新手。我的应用被审核拒绝,说明以下原因,

2.23 Apps must follow the iOS Data Storage Guidelines or they will be rejected

We found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

我没有将我的数据库文件存储在文档目录中。这是我的代码,

NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [libraryPath stringByAppendingPathComponent:@"DatabaseFolder"];
NSURL *pathURL = [NSURL fileURLWithPath:path];
BOOL isDirectory = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
if (isDirectory) {
return pathURL;
} else {
// Handle error. ".data" is a file which should not be there...
[NSException raise:@"'Private Documents' exists, and is a file" format:@"Path: %@", path];
}
}
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {

[NSException raise:@"Failed creating directory" format:@"[%@], %@", path, error];
}
return pathURL;

如何重现只有 App Review 或用户看到的崩溃或错误?

最佳答案

iOS Data Storage guideline document (需要登录才能查看)说,

Everything in your app’s home directory is backed up, with the exception of the application bundle itself, the caches directory, and temp directory.

这意味着即使您的 NSLibraryDirectory 目录内容也会备份到 iCloud。要解决此问题,您有以下选择,

  • 使用/tmp目录进行存储
  • 使用/Caches目录进行存储
  • 仅将/Documents 目录用于用户生成的无法重新创建的内容。
  • 使用 NSURL 的 setResourceValue:forKey:error: 方法设置文件的不备份属性。

此处介绍了如何将资源标记为不备份到 iCloud。

- (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;
}

希望对您有所帮助!

关于ios - App不在文档目录下存储任何内容但Appstore拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21900471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com