防止iCloud备份

时间:2012-05-21 23:26:42

标签: iphone objective-c ios5 icloud

我制作和应用人们下载内容,他们可以离线访问,它喜欢目录。但苹果拒绝它,因为它在iCloud中烘焙我正在做以下事情,但它似乎无法正常工作。

Funciones.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;
}

Update.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];
}

知道我做错了吗?

由于

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

也许是因为您的应用与iOS 5.0兼容。 备份变量仅在5.1之后可用。详情请http://developer.apple.com/library/ios/#qa/qa1719/_index.html#//apple_ref/doc/uid/DTS40011342