1

I see it's apparently possible to submit apps without Lion installed, but my app downloads some large files, which need to be saved according to Apple storage guidelines.

Including the code below, I can't even compile due to 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;
    }
}

How can I keep using this code while I've only got iOS 5.0 SDK in xcode?

(or is my desire moot because I literally cannot tell my app it supports iOS 5.1?)

Community
  • 1
  • 1
Thunder Rabbit
  • 5,405
  • 8
  • 44
  • 82

1 Answers1

0

I added a definition of that string constant if the ios version is not 5.1.

Here is how my implementation looks like:

+ (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;
        }
    }
Lio
  • 4,225
  • 4
  • 33
  • 40
  • Haha is that constant's value literally just the string of the constant's name? – Thunder Rabbit Jul 11 '12 at 23:10
  • Yes, if you print it, in iOS 5.1, it is just the constant's name. In any case, it won't be used when the ios version is less than 5.1. I could have used any value. – Lio Jul 12 '12 at 10:44