2012-05-27 31 views
1

我看到它顯然可能submit apps without Lion installed,但我的應用程序下載一些大文件,需要根據Apple storage guidelines保存。支持iOS 5.1 NSURLIsExcludedFromBackupKey [不備份]沒有安裝Lion?

包括下面的代碼,我甚至無法編譯由於Use of undeclared identifier 'NSURLIsExcludedFromBackupKey'

-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL{ 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.1")) { 
     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; 
    } 
} 

我怎樣才能繼續使用此代碼,而我只有在Xcode的iOS 5.0 SDK?

(或者是我的願望沒有實際意義,因爲我真的不能告訴我的應用程序,它支持的iOS 5.1?)

回答

0

我補充說字符串的定義,如果不變ios版本不是5.1。

這是我實現的樣子:

+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSString*) path 
    {   
     if (SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(@"5.01")) 
     { 
      const char* folderPath = [_privateDirectoryPath fileSystemRepresentation]; 
      u_int8_t attrValue = 1; 
      int result = setxattr(folderPath, kMobileBackupAttrName, &attrValue, sizeof(attrValue), 0, 0); 
      return result == 0; 
     } 
     else 
     { 
    #ifndef __IPHONE_5_1 
    #define NSURLIsExcludedFromBackupKey @"NSURLIsExcludedFromBackupKey" 
    #endif 
      NSError *error = nil; 
      NSURL* url = [NSURL fileURLWithPath:path]; 
      ASSERT_CLASS(url, NSURL); 
      BOOL success = [url setResourceValue: [NSNumber numberWithBool: YES] 
              forKey: NSURLIsExcludedFromBackupKey 
              error: &error]; 
      //Assert success     
      return success; 
     } 
    } 
+0

哈哈是常量的值字面常量的名字只是字符串? –

+0

是的,如果您打印它,在iOS 5.1中,它只是常數的名稱。在任何情況下,當ios版本低於5.1時都不會使用它。我可以使用任何價值。 – Lio