将文件保存到文档目录时如何更新文件的属性或键 [英] How to update an attribute or a key for a file while saving it in to documents directory
问题描述
我正在为我的iOS项目使用Dropbox API,这里是通过dropbox iOS SDK的REST调用来获取数据并将文件缓存到DocumentsDirectory中,以避免延迟从服务器加载文件
Hi I'm using Dropbox API for my iOS project, here through dropbox iOS SDK's REST calls I'm getting my data and I'm caching my files in to my DocumentsDirectory, so as to avoid delay of loading file from server every time by service calls.
-
因此,一旦从保管箱服务器下载了文件,我会将其保存在我的应用程序文档目录中
So once a file downloaded from dropbox server I'll be keeping it inside my apps documents directory and for further reference I'm fetching from my documents directory.
这里的问题是,每当文件被更新或修改时,我都会得到一些参考。我如何将这个修订号与相应的文件一起保存,以便下次当我想要此文件时,我将检查修订号,如果匹配,则从本地目录中获取,否则调用服务。
Here the problem is whenever a file is updated or modified a new revision number i will get some how i need to save this revision number along with the respective file, so that next time when i want this file i will check the revision number, if it matches then take from my local directory else invoke service.
现在如何保存(更新)此修订号字符串。
Now how can i save(update) this revision number string.
我在将文件保存到文档目录时尝试了以下代码段,但是 setAttributes 无法添加用户定义的文件属性属性,我们只能更新默认属性
I tried below snippet while saving a file to Documents directory but setAttributes can't add userDefined file attribute properties, we can only update default properties
NSDictionary *revisionDict = [NSDictionary dictionaryWithObject:item.rev forKey:@"revision"];
[[NSFileManager defaultManager] setAttributes:revisionDict ofItemAtPath:DocDirPath error:nil];
推荐答案
如果要操作扩展属性,则必须使用BSD级别的API。特别是标头< sys / xattr.h>
和类似 getxattr
, setxattr
, listxattr
, removexattr
。文档在相应的人
页面中。
If you want to manipulate the extended attributes you must use BSD level APIs. Specifically the header <sys/xattr.h>
and functions like getxattr
, setxattr
, listxattr
, removexattr
. Documentation is in the corresponding man
pages.
这篇关于将文件保存到文档目录时如何更新文件的属性或键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!