【问题标题】:backing up prevent from the app in iCloud备份阻止从 iCloud 中的应用程序
【发布时间】:2011-12-26 21:28:33
【问题描述】:

apple storage guidelines 的方式给我带来了更多问题,因为我从 Documents 目录维护的大部分数据(文件、数据库和某种与应用程序相关的东西)。最近我上传了一个二进制文件到应用程序商店被拒绝了,苹果向我提供了一份报告 根据这一点我将更改我的代码如下

- (NSString *)applicationDocumentsDirectory {
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSURL *pathURL= [NSURL fileURLWithPath:documentPath];
[self addSkipBackupAttributeToItemAtURL:pathURL];
return documentPath;

}

 - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];

const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}

我的问题:

1.我可以直接对文档目录使用 addSkipBackupAttributeToItemAtURL: 方法来禁止我在文档目录中的所有文件的 iCloud 备份。

2.上面提到的代码足以让我的应用在应用商店中获得批准,以防我的最后一个二进制文件由于“不备份”属性而被拒绝,因为我的文档目录中不包含“不备份”属性。

【问题讨论】:

  • 我遇到了同样的问题。由于您遇到的同样问题,我的应用程序也被拒绝了。您是将文件位置更改为库路径还是尝试“不备份”?
  • 我仍然处于两难境地,因为设备缓存空间不足,临时文件将被删除。我的整个应用程序依赖于文档目录。如果我使用“不备份”,它将适用于除 ios5.0 以外的所有版本。我想再考虑几天。
  • 我的应用再次被拒绝。因为 iCloud。我已将文件夹目录更改为库路径,并将其标记为“不备份”。我还在库目录中存储了一些数据,但没有给它们“不要标记”。
  • 嘿,你解决问题了吗?告诉我你是怎么解决的?
  • 我上传了二进制文件等待重播。

标签: iphone ipad ios5 wifi icloud


【解决方案1】:

您应该能够将此属性设置为文件夹以避免备份整个文件夹。

但是请注意,对完整的 Documents 文件夹执行此操作可能不是一个好方法。首先,这将造成您的应用程序没有备份内容的情况,因此在手机恢复时应用程序将处于原始状态。我也可以想象这不是“苹果想要的”方式,因此可能导致应用程序被拒绝(总是猜测)。如果可能,我会在 Document 目录中为您的非备份内容创建一个子文件夹,并将所有内容放在那里(如果您已经在商店中有此应用程序的版本,这可能需要一些迁移代码)。

请注意,存储指南确实允许在 Documents 目录中存储用户创建/不可重新创建的内容,您只需标记下载的内容等不能放入 Caches 目录的内容(例如,如果用户预计此内容可以离线使用)。

【讨论】:

  • 感谢您的快速重播。我将尝试创建一个文件夹并将我的所有文件放在其中。我将提供“不备份”属性。
【解决方案2】:

使用此功能

-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
if (&NSURLIsExcludedFromBackupKey == nil) {
    // iOS 5.0.1 and lower
    u_int8_t attrValue = 1;
    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;

}
else {
    // First try and remove the extended attribute if it is present
    int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
    if (result != -1) {
        // The attribute exists, we need to remove it
        int removeResult = removexattr(filePath, attrName, 0);
        if (removeResult == 0) {
            NSLog(@"Removed extended attribute on file %@", URL);
        }
    }

    // Set the new key
    NSError *error = nil;
    [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
    return error == nil;
}
 }

这是实现的代码。谢谢

【讨论】:

    猜你喜欢
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 2019-08-16
    • 2016-01-19
    • 2015-07-30
    相关资源
    最近更新 更多