【问题标题】:NSFileManager Attributesforitem fails and returns nullNSFileManager Attributesforitem 失败并返回 null
【发布时间】:2012-11-03 16:02:44
【问题描述】:

现在我正在开发一个需要 NSFileManager 的 iOS 应用程序,但是当我执行 attributesOfItemAtPath: 方法时,它返回 null。这在 NSData 和 dataWithContentsOfFile: 方法上也失败了。我不明白为什么会这样。我使用的文件 URL 看起来像这样:file://localhost/private/var/mobile/Applications/597DE145-33D7-4F92-AE95-029D5CF15291/tmp/Kv7DWqtRWH7WnN47HdDW。我怀疑这可能与 URL 有关,但我不确定。

【问题讨论】:

    标签: ios objective-c filesystems nsfilemanager filepicker.io


    【解决方案1】:

    您需要将NSURL 转换为路径,以便与任何采用字符串的NSFileManager 方法一起使用。通过在 URL 上调用 path 方法来执行此操作。

    NSURL *someURL = ... // some file URL
    NSString *path = [someURL path]; // convert the file:// URL to a file path
    NSDictionary *info = [[NSFileManager defaultManager] attributesOfItemAtPath:path];
    

    【讨论】:

    • 我和你在一起:)
    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 2019-01-02
    • 2016-03-22
    • 2017-06-29
    • 2014-02-14
    相关资源
    最近更新 更多