【发布时间】:2013-09-29 02:58:56
【问题描述】:
在我的应用程序启动时,它会将我的资源文件夹中的一个库复制到 iOS 设备上的文档目录中。这是第一次启动时的一次性过程,再也没有碰过。 Apple 今天拒绝了我的应用,原因如下:
我们发现您的应用不遵循 iOS 数据存储 指南,不符合 App Store Review 指导方针。
iOS 数据存储指南指出,只有 用户使用您的应用创建,例如文档、新文件、编辑等, 应由 iCloud 备份。
您的应用使用的临时文件应仅存储在 /tmp 目录;请记住删除存储在此位置的文件 当用户退出应用程序时。
可以重新创建但必须保留才能正常运行的数据 您的应用 - 或者因为客户希望它可以离线使用 使用 - 应标有“不备份”属性。对于
NSURL对象,添加NSURLIsExcludedFromBackupKey属性以防止 相应的文件被备份。对于CFURLRef对象,使用 对应kCFURLIsExcludedFromBackupKey属性。
我不确定如何设置不备份属性或者它是否是我需要的。谁能告诉我这是如何根据我的代码完成的?
-(void) progress
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
NSString *dataPath = [documentPath stringByAppendingPathComponent:pathWeSet];
if (![fileManager fileExistsAtPath:dataPath]) {
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *dataPath = [bundlePath stringByAppendingPathComponent:pathWeSet];
timer = [NSTimer timerWithTimeInterval:0.4 target:self selector:@selector(updateProgressView) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[timer fire];
if (dataPath) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[fileManager copyItemAtPath:dataPath toPath:dataPath error:nil];
});
}
}
}
谢谢
【问题讨论】:
-
为什么将数据复制到Documents文件夹中?数据是什么?数据是用户更新的还是只读的?
-
@rmaddy 这是一个库,为了简单起见,我每次使用应用程序时都需要转移到文档目录中阅读。它被传输一次,然后在每次使用应用程序时读取。谢谢!
-
如果它是只读的,那么没有理由将它复制到任何地方。每次从资源包中读取即可。
-
@rmaddy 这很慢,不能那样工作。我知道这是一个模糊的答案,但我对此进行了彻底的测试并找到了支持文档。因此,无需深入,它“必须”被复制。谢谢
标签: ios objective-c