2012-05-28 54 views
4

我最近的iOS應用程序剛剛被拒絕,因爲應用程序正在將數據存儲在文檔中,所以它由iCloud備份,由於數據是從服務器下載的,因此這是不允許的。即使在執行addSkipBackupAttributeToItemAtURL時仍然可以備份到iCloud?

我正在嘗試重建代碼,並且在將數據存儲到文件夾中的Calles Application Support中時遇到了困難。

但即使我使用addSkipBackupAttributeToItemAtURL它仍然顯示爲備份到iCloud。

我只針對5.1,所以它不是一個版本問題。

我在這裏補充下受影響的代碼:

NSString *newPath = [NSMutableString stringWithFormat:@"%@/Library/Application Support/", NSHomeDirectory()]; 

    if (![[NSFileManager defaultManager] fileExistsAtPath:newPath]) //Does directory already exist? 
    { 
     if (![[NSFileManager defaultManager] createDirectoryAtPath:newPath 
             withIntermediateDirectories:NO 
                 attributes:nil 
                  error:&error]) 
     { 
      NSLog(@"Create directory error: %@", error); 
     } 

    } 

    NSString *guidesPath = [newPath stringByAppendingPathComponent:@"/Guides"]; 
    if (![[NSFileManager defaultManager] fileExistsAtPath:guidesPath]) //Does directory already exist? 
    { 
     if (![[NSFileManager defaultManager] createDirectoryAtPath:guidesPath 
             withIntermediateDirectories:NO 
                 attributes:nil 
                  error:&error]) 
     { 
      NSLog(@"Create directory error: %@", error); 
     } 

    } 

    NSString *dataPath = [guidesPath stringByAppendingPathComponent:dbName]; 

    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) 
    { 
     if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath 
             withIntermediateDirectories:NO 
                 attributes:nil 
                  error:&error]) 
     { 
      NSLog(@"Create directory error: %@", error); 
     } 

    } 

    NSString *newGuidesPath = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSURL *guidesURL = [NSURL URLWithString:newGuidesPath]; 
    [self addSkipBackupAttributeToItemAtURL:guidesURL]; 

    NSString* path = [dataPath stringByAppendingPathComponent: 
         [NSString stringWithString: finalName] ]; 
    if (![fileManager fileExistsAtPath:path]) { 
     [myData writeToFile:path atomically:YES]; 
     NSString *docFile = [dataPath stringByAppendingPathComponent: @"guideid.txt"]; 
     [[guideID dataUsingEncoding:NSUTF8StringEncoding] writeToFile:docFile atomically:NO]; 
     DLog(@"Saved database here:%@", path); 
    }else{ 
     DLog(@"Already exists, no need to copy"); 
    } 

} 

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL 
{ 


assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); 

NSError *error = nil; 
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] 
           forKey: NSURLIsExcludedFromBackupKey error: &error]; 
if(!success){ 
    NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); 
} 

return success; 
} 

回答

9

實際上找到了一個解決方案, 我編碼了不需要的URL。 剛剛將該文件夾

NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath]; 
    [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL]; 

而且跳過了排除法,只是標記它的代碼,這似乎在裏面工作。

0

你從iCloud中設置嘗試創建新備份您的設備上?

+0

這實際上解決了我的問題。 – user3687

相關問題