【问题标题】:Prevent iCloud Backup阻止 iCloud 备份
【发布时间】:2012-05-21 23:26:42
【问题描述】:

我制作了一个应用程序,人们可以下载内容,他们可以离线访问它,它就像一个目录。但是 Apple 拒绝了它,因为它在 iCloud 中烘烤,我正在执行以下操作,但它似乎不起作用。

函数.m

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

更新.m

- (void)updateImg:(NSString *)tipo {

    //tomamos el ultimo update
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSTimeInterval time = [defaults doubleForKey:@"lastUpdate"];
    NSLog(@"%f", time);

    CatalogoAppDelegate *app = [[UIApplication sharedApplication] delegate];

    NSString *post = [NSString stringWithFormat:@"lastUpdate=%f", time];
    NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
    NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
    NSString *url = [NSString stringWithFormat:@"%@iPhone/update%@Img.php", app.serverUrl, tipo];
    [urlRequest setURL:[NSURL URLWithString:url]];
    [urlRequest setHTTPMethod:@"POST"]; 
    [urlRequest setHTTPBody:postData];

    NSData *urlData; 
    NSURLResponse *response; 
    NSError *error;
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; 
    if(urlData) {


        NSString *aStr = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]autorelease];
        //NSLog(@"%@: %@", tipo, aStr);
        NSArray *temp = [aStr componentsSeparatedByString:@";"];

        //Direccionl Local de la APP
        NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

        for (int i=0; i<[temp count]; i++) {

            NSString *tempImg = [NSString stringWithFormat:@"%@", [temp objectAtIndex:i]];
            //NSLog(@"%@", tempImg);

            //pedimos cada url
            NSURL *tempURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@images/%@/%@", app.serverUrl, tipo, tempImg]];
            //[Funciones addSkipBackupAttributeToItemAtURL:tempURL];
            UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:tempURL]];
            NSLog(@"%@images/%@/%@", app.serverUrl, tipo, tempImg);
            NSString *pngFilePath = [NSString stringWithFormat:@"%@/%@", docDir, tempImg];
            NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
            [data1 writeToFile:pngFilePath atomically:YES];

            NSURL *backUrl = [NSURL fileURLWithPath:pngFilePath];
            [Funciones addSkipBackupAttributeToItemAtURL:backUrl];

        }

    }
    [self performSelectorInBackground:@selector(finUpdate) withObject:nil];
}

知道我做错了什么吗?

谢谢

【问题讨论】:

    标签: iphone objective-c ios5 icloud


    【解决方案1】:

    setxattr 提供指示成功或错误的结果,Apple 的 addSkipBackupAttributeToItemAtURL: 方法检查错误并将此信息传递回您的代码。您的代码只是忽略它。首先确定它是否返回错误。

    【讨论】:

    • 嗨@Jim,该方法返回True。我检查它提供的每个网址。但我的问题是我需要在哪一部分添加该部分或在下载之前添加它?
    • 你确定吗?您提供的代码根本不检查返回值。
    • 嗨@Jim 不,我没有在那里检查它,但我调试它并返回 1 = true。但是你认为它的实现正确吗?
    • 谢谢吉姆。没错,但 addSkipBackupAttributeToItemAtURL: 是在保存之前。而且我需要删除该应用程序并进行备份,因为它会使用以前的备份进行恢复,并且我认为它正在备份,但事实并非如此。苹果已经接受了。谢谢:)
    【解决方案2】:

    可能是因为您的应用与 iOS 5.0 兼容。 不备份变量仅从 5.1 开始可用。详情看这里http://developer.apple.com/library/ios/#qa/qa1719/_index.html#//apple_ref/doc/uid/DTS40011342

    【讨论】:

    • 嗨@CedricSoubrie 不,这是因为该应用程序有一个我永远不会擦除的备份缓存:P
    猜你喜欢
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2019-08-16
    • 2015-01-14
    • 2012-10-12
    • 2016-05-27
    • 2013-02-03
    相关资源
    最近更新 更多