1

Lion をインストールせずにアプリを提出することは明らかに可能ですが、私のアプリはいくつかの大きなファイルをダウンロードするため、 Apple ストレージ ガイドラインに従って保存する必要があります。

以下のコードを含めて、次の理由でコンパイルすることさえできません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 をサポートしていることを文字通り伝えることができないので、私の欲求は無意味なのでしょうか?)

4

1 に答える 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;
        }
    }
于 2012-07-11T13:29:20.057 に答える