0

在此处输入图像描述 我已在信息中启用“使用应用程序支持 iTunes 文件共享”以下载 pdf、excel,我使用 Realm 作为数据库。领域不需要的文件default.realm, default.realm.lock , default.realm.management 我无法在 iOS14 中删除,该文件未打开我使用此代码删除辅助文件 let folderPath = realm.configuration.fileURL!。删除LastPathComponent().path

    // Disable file protection for this directory
    try! FileManager.default.setAttributes([FileAttributeKey(rawValue: FileAttributeKey.protectionKey.rawValue): FileProtectionType.none],
                                           ofItemAtPath: folderPath)

让路径 = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,

                                                            .userDomainMask,

                                                            true)

    let oldPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)

    let applicationSupportDirectoryPath = paths.first

           

    let  realmPath = applicationSupportDirectoryPath?.appending("ofline.realm")

            Realm.Configuration.defaultConfiguration.objectTypes = objectTypes

            

            var realmConfig = Realm.Configuration.defaultConfiguration

            realmConfig.fileURL = URL(fileURLWithPath: realmPath!)

            realm = try! Realm(configuration: realmConfig)

                do{

        

                    try FileManager.default.removeItem(atPath: oldPaths[0].appending("ofline.realm"))

                    try FileManager.default.removeItem(atPath: oldPaths[0].appending("ofline.realm.lock"))

                    try FileManager.default.removeItem(atPath: oldPaths[0].appending("ofline.realm.management"))

                    



                }

                catch{

                }

但不删除该文件

4

0 回答 0