2012-05-27 30 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