我的应用正在占用我iPad存储上的幻像空间

问题描述 投票:0回答:1

所以,我正在为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个回答
0
投票

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

因此,我存储在.documentDirectory上然后删除的所有图像都放在.trash文件夹中,我不知道如何在iPad上观看,只是不让我知道这是怎么回事。我想我对iStuff还不是很熟悉。

所以我不得不在该文件夹上运行清理序列才能清除它..

© www.soinside.com 2019 - 2024. All rights reserved.