【发布时间】:2012-03-16 03:39:54
【问题描述】:
我正在开发支持 iTunes 文件共享功能的 iOS 项目。目标是实时跟踪传入/更改的数据。
我正在使用 Apple 示例代码中的 (有点修改) DirectoryWatcher 类 也试过this source code。
数据是 NSBundle (*.bundle),一些包在 100-500 MB 范围内,取决于其内容,一些视频/音频内容。捆绑包中包含基于 xml 的描述符文件。
问题是上述代码中的任何一个触发通知或在数据刚刚开始复制时而不是在复制/更改/删除过程完全完成时。
接下来尝试:
检查文件属性:
NSDictionary *fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:[contURL path] error:nil];
BOOL fileBusy = [[fileAttrs objectForKey:NSFileBusy] boolValue];
寻找fileSize的变化:
dispatch_async(_checkQueue, ^{
for (NSURL *contURL in tempBundleURLs) {
NSInteger lastSize = 0;
NSDictionary *fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:[contURL path] error:nil];
NSInteger fileSize = [[fileAttrs objectForKey:NSFileSize] intValue];
do {
lastSize = fileSize;
[NSThread sleepForTimeInterval:1];
fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:[contURL path] error:nil];
fileSize = [[fileAttrs objectForKey:NSFileSize] intValue];
NSLog(@"doing job");
} while (lastSize != fileSize);
NSLog(@"next job");
}
);
还有其他解决方案吗?
上述解决方案适用于 bin 文件,但不适用于 .bundle(因为 .bundle 文件实际上是目录)。为了使其与 .bundle 一起使用,您应该迭代 .bundle 中的每个文件
【问题讨论】:
标签: objective-c ios filesystems