【问题标题】:My app is taking phantom space on my iPad's storage我的应用程序占用了我的 iPad 存储空间
【发布时间】:2020-04-13 09:41:22
【问题描述】:

所以,我正在开发一款涉及绘图的 iPad 应用。 它将文件存储在两个地方: userDocument :

FileManager.default.url( for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true )

和 appSupportFolder:

FileManager.default.url( for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true )

现在发生的情况是,iOS 告诉我我的应用程序占用了 18GB 磁盘空间,即使我清除了所有文档目录(使用查找器,因为这个是可见的)和支持文件夹:

if  let suppPath = try? FileManager.default.url( for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true ),
    let URLs = try? FileManager.default.contentsOfDirectory( atPath: suppPath.path )
{
    for url in URLs
    {
        let completePath = suppPath.appendingPathComponent( url )
        try? FileManager.default.removeItem( at: completePath )
    }
}

在这之后,我什至不知道如何检查这个文件夹的内容,但我运行了这个:

func ScanDir( url: URL, depth: Int )
{
    var string = ""
    for _ in 0 ..< depth
    {
        string += "----"
    }

    string += "\(url.lastPathComponent)"
    debugPrint( string )

    if let URLs = try? FileManager.default.contentsOfDirectory( atPath: url.path )
    {
        for urlstring in URLs
        {
            ScanDir( url: url.appendingPathComponent( urlstring ), depth: depth+1 )
        }
    }
}

扫描的结果就是

"Application Support"

以前,我可以看到我所有的项目、导出的文件、画笔等... 所以它似乎奏效了。 但是,该应用程序仍然高达 18GB。

然后我可以卸载它,但是一旦我重建应用程序,它就会恢复。 我现在很迷茫……

【问题讨论】:

    标签: ios memory filesystems diskspace


    【解决方案1】:

    好吧,事实证明,iOS 会自动将从 .documentDirectory 中删除的所有内容放入同一文件夹中的隐藏垃圾箱中。

    因此,我存储在 .documentDirectory 上然后删除的所有图像都进入了 .trash 文件夹,我不知道如何在 iPad 上查看,只是不会让我知道发生了这种情况。我想我对 iStuff 还不是很熟悉。

    所以我不得不对这个文件夹运行我的清理程序来摆脱它..

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 2014-03-04
      • 2018-08-29
      • 2011-07-11
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 2012-03-25
      相关资源
      最近更新 更多