iphone - 检查文件是否更新

标签 iphone ios objective-c nsfilemanager

我有iOS应用程序。在文件目录中有一些文件。我需要检查这些文件是否已被编辑或替换。正确的做法是什么?我应该对文件进行某种哈希处理还是最后一次编辑时间(如何在iOS中获得该时间)还是有一些更好的方法来实现呢?

最佳答案

您可以使用以下代码获取文件修改日期:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary* attributes = [fileManager attributesOfItemAtPath:path error:nil];

if (attributes != nil) {
    NSDate *date = (NSDate*)[attributes objectForKey:NSFileModificationDate];
    NSLog(@"Last modification date: %@", [date description]);
} else {
    NSLog(@"Not found");
}

here您可以找到attributesOfItemAtPath:error:函数的文档,而here您可以获取的文件属性列表

关于iphone - 检查文件是否更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15189334/

相关文章:

iphone - UIDatePicker 与 UIApplicationSignificantTimeChangeNotification

ios - Swift 中的流控制 - AVAudioPlayer

iphone - uibutton 和 uilabel 的 UILongPressGestureRecognizer 问题

ios - 如何删除整个 NSAttributedString block

ios - SwiftUI - 动态刷新 UINavigationBar.appearance().backgroundColor

ios - 处理应用程序在 UILongPressgestureRecognizer 中间进入后台

iphone - 为什么此代码显示的日期是 SAT,而在 NSDateComponent setWeekday 中我使用 1 表示 SUN?

iphone - UIActivityViewController 第一次卡住

ios - 如何使状态栏与导航栏颜色相同?

objective-c - UrlByAppendingPathComponent 与 UrlByAppendingPathExtension