English 中文(简体)
支持 iOS 5.1 NSURLIs 排除来自 BackupKey 的例外 [不备份] 。 未安装狮子?
原标题:support iOS 5.1 NSURLIsExcludedFromBackupKey [do not backup] without Lion installed?
  • 时间:2012-05-27 12:46:28
  •  标签:
  • ios
  • ios5

我发现显然有可能 上传没有狮子号安装的应用程序 ,但我的应用程序下载了一些大型文件,需要根据Apple 储存准则 保存。

包括以下代码,由于使用未申报标识符NSURLIs的 < code > 使用未申报标识符NSURLIs Exclate from BackupKey ,我甚至无法编译:

-(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.0SDK的时候 我怎么能一直使用这个代码呢?

(或我的欲望没有意义,因为我实在不能告诉我的应用程序它支持 iOS 5.1? )

最佳回答

如果 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;
        }
    }
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签