2012-05-21 77 views
2

我製作和應用程序讓人們下載內容,並且可以脫機訪問它,它喜歡目錄。但蘋果拒絕它,因爲它在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

setxattr提供指示成功或錯誤,以及錯誤蘋果addSkipBackupAttributeToItemAtURL:方法檢查結果,並將此信息反饋給你的代碼。你的代碼簡單地忽略它。從確定它是否返回錯誤開始。

+0

嗨@Jim那個方法它返回True。我檢查它提供的每一個網址。但我的問題是我需要在那部分或下載它之前添加哪部分? – Edig

+0

你確定嗎?你提供的代碼根本不檢查返回值。 – Jim

+0

嗨@Jim不,我不檢查它,但我調試它,它返回1 =真。但是你認爲這個實現是否正確? – Edig